ColdFusion/Java - "The build method was not found" - java

We are using some org.apache classes as part of implementing WS Security for a webservice.
variables.paths = arrayNew(1);
variables.paths[1] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\wss4j-1.5.8.jar";
variables.paths[2] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\xmlsec-1.4.2.jar";
variables.loader = createObject("component","lib.javaloader.JavaLoader").init(loadPaths=variables.paths,loadColdFusionClassPath=true);
variables.WSConstantsObj = loader.create("org.apache.ws.security.WSConstants");
variables.messageClass = loader.create("org.apache.ws.security.message.WSSecUsernameToken");
variables.secHeaderClass = loader.create("org.apache.ws.security.message.WSSecHeader");
The following code:
<cfset var msg = getMessage()>
produces:
The following code:
<cfset var secHeader = getSecHeader()>
produces:
The following code:
<cfset var env = soapEnv.getDocumentElement()>
produces:
env.getOwnerDocument()
produces a huge structure (too big to include here), which you can view here.
However, the following code:
<cfset e = msg.build(env.GetOwnerDocument(),secHeader)>
throws the error:
The build method was not found.
Either there are no methods with the specified method name and argument types or the build method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
However the Build() method certainly exists, as per the yellow highlight in the first screenshot.
The error message talks about "...use the javacast function to reduce ambiguity". If this were the problem, how would I apply this solution?

It's not that "build()" doesn't exist but that your signature is incorrect. The 2 arguments for the build method are:
env.GetOwnerDocument(),secHeader
We know that that secHeader is of the class
org.apache.ws.security.message.WSSecHeader
Because your cfdump indicates as much.
That likely means that "env.GetOwnerDocument" is not returning an object of the class
org.w3c.dom.Document
It may be returning an error or a primitive or another class. Instantiate envGetOwnerDocumet() and dump that out and check the class. I think it is screwing up the method signature. That's my best guess anyway.

Related

How to pass Table Field as import parameter to SAP RFC using JAVA(JCO3)

Following i my code in JCO3.0 to connect to RFC and get the data from function module:
try {
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME);
JCoFunction function = destination.getRepository().getFunction("funtion_abap");
***function.getImportParameterList().setValue("IM_ID_NAME", "MTC_ZPR008_TEMPB");***
function.execute(destination);
JCoTable table = function.getTableParameterList().getTable("export_table");
}
catch(Exception e){
}
Following is my ABAP function:
CALL FUNCTION 'funtion_abap' DESTINATION m_vsyid
EXPORTING
IM_ID_NAME = table_vname
IMPORTING
export_table = table_tvarvc
EXCEPTIONS
system_failure = 1
communication_failure = 2
resource_failure = 3
OTHERS = 4.
following is an error m getting while passing String as import parameter while it wants Table field as import parameter:
Exception in thread "main" com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert a value of 'MTC_ZPR008_TEMPB' from type java.lang.String to TABLE at field IM_ID_NAME
at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:468)
at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:462)
at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:2958)
at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:4074)
at com.amgen.rfc.RFC_Connection.main(RFC_Connection.java:47)
Please tell me how to solve this problem.
The RFC definition and your code are in direct opposition. According to the ABAP function (as far as I read it) the result of the call is the value in field IM_ID_NAME and the table is the input parameter.
I'm not 100% familiar with the declaration of RFCs in ABAP (I only know the Java side of it), but if I interpret the error message correctly, the table seems to be in the input parameter list rather than the table parameter list (not usual but not never seen before, either). So instead of getTableParameterList you will possible have to call getInputParameterList. Also you should omit the setting of the field IM_ID_NAME because that's the response value and resides in the output parameter list.
I know the question is quite old but someone may find my response useful one day since I had the same problem:
JcoTable tab = function.getImportParameterList().getTable("IM_ID_NAME");
tab.appendRow();
tab.firstRow(); // I'm not sure if this is actually reqiured
tab.setValue("PARAM_NAME", paramValue);

Calling methods between groovy scripts with correct parameters

I just started learning about groovy and trying to transpose my java code to groovy scripts. Usually java allows you have a class with only methods that you can call from other classes. I wanted to translate that to groovy. I have in one file - lets call it File1- a method like this:
def retrieveData(String name){
// do something
}
and in the second file, File2, I call File1 like this:
def file1Class = this.class.classLoader.parseClass(new File("../File1.groovy"))
and then try to call the method in File1 like this:
def data = file1Class.retrieveData("String")
but it keeps giving me this error - MissingMethodException:
groovy.lang.MissingMethodException: No signature of method: static File1.retrieveData() is applicable for argument types: (java.lang.String) values: [String] Possible solutions: retrieveData(java.lang.String)
so it does recognize that I am sending in the correct number of parameters and even the correct object, but it isn't running the method as it should?
Is there something I am missing? I tried to remove the object definition from the method - in other words - like this:
def retrieveData(name){
// do something
}
but that didn't work either. I am clueless about what the next step would be. Can anyone please help push me in the right direction? I would greatly appreciate it.
See the answer provided in this StackOverflow reponse.
Use the GroovyScriptEngine class. What does the GroovyScriptEngine do? From the docs:
Specific script engine able to reload modified scripts as well as
dealing properly with dependent scripts.
See the example below.
def script = new GroovyScriptEngine( '.' ).with {
loadScriptByName( '..\File1.groovy' )
}
this.metaClass.mixin script
retrieveData()
Note how we use the loadScriptByNamemethod to
Get the class of the scriptName in question, so that you can
instantiate Groovy objects with caching and reloading.
This will allow you to access Groovy objects from files however you please.

The constructor TFSTeamProjectCollection(String) is undefined

Trying to implement the Java SDK, following the tutorial here: https://blogs.msdn.microsoft.com/bharry/2011/05/16/announcing-a-java-sdk-for-tfs/
I have the libraries imported, but getting a compilation error
TFSTeamProjectCollection tpc =
new TFSTeamProjectCollection(BASEURL);
BASEURL is a string I defined earlier in the code.
The error is: The constructor TFSTeamProjectCollection(String) is undefined
Does anyone know how to resolve this issue?
Well, studying the C# side of things ( see here ) I can't find a constructor that would only take a String argument.
There is only a single argument constructor taking a Uri.
In other words: the fact that you your string contains a Url; and that you named it a BASEURL doesn't magically turn it from a String into a URL or URI class object.
Guessing: the ctor wants an argument of type java.net.URL which you could probably create with something like new URL(BASEURL); instead of just passing BASEURL to that constructor.
The thing is: in order to actually understand which constructors that Team Foundation class has; one would need access to the corresponding SDK from Microsoft - which you probably downloaded and and have in place. So, the only thing that you need to do ... read the javadocs!

How to call .NET method of DocuWare API with Nullable arguments from Java

When I try to invoke the .NET method – ‘Create’ from Java using Javonet I get a message the method does not exist because I am not passing the correct parameters –
DocuWare.Platform.ServerClient.ServiceConnection
Create(System.Uri,
System.String,
System.String,
System.String,
System.Nullable`1[DocuWare.Platform.ServerClient.DWProductTypes],
System.Net.Http.HttpMessageHandler,
System.Net.Http.Headers.ProductInfoHeaderValue[]
)
My code is –
NObject objUri = Javonet.New("Uri","http://<IP-address>/DocuWare/Platform");
NType serviceConnectionClass = Javonet.getType("DocuWare.Platform.ServerClient.ServiceConnection");
NObject objProductInfoHeaderValue = Javonet.New("System.Net.Http.Headers.ProductInfoHeaderValue","DocuWare+.NET+API+Test+Client", "1.0");
NObject[] objProductInfoHeaderValueArray = new NObject[] {objProductInfoHeaderValue};
NType typeHttpMessageHandler = Javonet.getType("System.Net.Http.HttpMessageHandler");
NType typeNullable = Javonet.getType("System.Nullable");
serviceConnectionClass.invoke("Create",objUri,"admin","admin","<company-name>",typeNullable,typeHttpMessageHandler,objProductInfoHeaderValueArray);
My main problem is not knowing how to generate ‘Nullable’ objects for –
DocuWare.Platform.ServerClient.DWProductTypes
System.Net.Http.HttpMessageHandler
System.Net.Http.Headers.ProductInfoHeaderValue[]
I don't think this is a problem with JavONet, but I need to get past this problem before I can perform a Proof-of-concept
Here is the link to the Docuware Platform –
http://help.docuware.com/sdk/platform-eagle/html/66b2ed1e-2aef-452a-97cd-5014bbf0242b.htm
I am running the Test using Tomcat app server and JSP. I know the .NET .dll are being found and the Javonet library is being correctly activated.
Thanks in advance for any help.
Normally for nullable arguments you can pass either the regular target type in your case some enum value of "DWProductTypes" or if you want to pass null just pass the "null";
So you should make the call:
serviceConnectionClass.invoke("Create",objUri,"admin", "admin","Intermodal Tank",new NEnum("DWProductTypes","DocuWareClient"),typeHttpMessageHandler,objProductInfoHeaderValueArray);
All possible values for DWProductTypes you can find here:
http://help.docuware.com/sdk/platform/html/T_DocuWare_Platform_ServerClient_DWProductTypes.htm
Here you find more about using enumerations:
https://www.javonet.com/quick-start-guide/#Enums_How_To_Work_With_Enums
or pass null:
serviceConnectionClass.invoke("Create",objUri,"admin", "admin","Intermodal Tank",null,typeHttpMessageHandler,objProductInfoHeaderValueArray);
For argument HttpMessageHandler just create the instance:
NObject typeHttpMessageHandler = Javonet.New("SomeConcreteTypeInheritingFromHttpMessageHandler");
For ProductInfoHeaderValue array you should create Java array of NObjects and pass it as argument:
NObject[] objProductInfoHeaderValueArray = new NObject[1];
objProductInfoHeaderValueArray[0] = Javonet.New("ProductInfoHeaderValue","productName","version");

ColdFusion found 0 methods that match the provided arguments

I'm trying to implement a .Net component in a Coldfusion application (this is on my development machine running CF 11.
I set up the object like this:
<cfset dll = ExpandPath('./com/Interop.CADXLib.dll')>
<cfobject class="CADXLib.CadX" type=".NET" name="cadx" assembly="#dll#”>
That’s in my application.cfc, in the onRequestStart() method. Then in my index.cfm I call:
<cfdump var="#cadx#”>
The object dumps just fine. I can see all the internal methods, including the one I need to get things going, the OpenDesign() method, which (in theory) opens a local file and reads the contents.
So next I set the actual filename I want to access:
<cfset thisfile="1571269P01R01_ARTIOS.ARD">
<cfset thispath=getDirectoryfromPath(getCurrentTemplatePath())>
<cfset thisfile=thispath & thisfile>
This works, and outputting “thistfile” gives me the correct path location. So now I call the actual method:
<cfset result=cadx.OpenDesign(thisfile,0)>
That’s where I get stuck. I get this error:
Either there are no methods with the specified method name and argument types or the OpenDesign method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
I try the javacast function:
<cfset result=cadx.OpenDesign(JavaCast("string",thisfile),JavaCast("int",0))>
Same error. Method not found. But based on the dump, the method is clearly there.
Has anyone encountered this or something similar?

Categories