I've managed to consume a webservice that uses a complex data type as one of
its input parameters on my [h]DEVELOPMENT[/h] machine (WinXP, CF Dev
7,0,0,91690). I get the following error when I move the code up to our
[h]STAGING[/h] server (Win2003, CF Standard 7,0,2,142559):
[hr]
[b]Error converting CFML arguments to Java classes for web service invocation.
[/b]
Unable to create web service argument class [Ljava.lang.String;. Error:
java.lang.InstantiationException: [Ljava.lang.String;. Often this is because
the web service defines an abstract complexType as an input to an operation.
You must create an actual instance of this type in Java.
[hr]
It looks like my development server is creating the propper stub objects for
the complex types (i.e. class files in the C:\CfusionMX7\stubs\ directory) ,
but the staging server is not. I'm hiting the same WSDL from both servers and
the complex type is clearly defined in the wsdl, so I don't know why one server
would interpret it correctly and the other can not. Is this a bug in CF
webservice implementation?
Can anyone tell me:
1) How I can get my staging server (Win2003, CF Standard 7,0,2,142559) to
generate the propper stubs
or
2) A work around? I know I CAN use wsdl2java.exe to generate the stubs
manually, I'm just having a hard time with the HOW:
- I've executed wsdl2java.exe [url-of-wsdl] to create the java files
- From what I've read on the forums, I think I should be able to use the code
below to compile the java objects into stubs, but it doesn't seem to work:
[li] I can generate the class file for the specific missing stub, then move it
to the correct directory in cfusionmx7/stubs, but I still get the same
error[/li]
[li] If i try to generate stubs for all the java files, I get errors.[/li]
The code I use to compile the java files is listed below:
javac -source 1.4 -deprecation -classpath
C:/CFusionMX7/lib/axis.jar;C:/CFusionMX7/lib/xml-apis.jar;C:/CFusionMX7/lib/saaj
.jar;C:/CFusionMX7/lib/jaxrpc.jar;.
C:/CFusionMX7/runtime/bin/com/mycompany/mypackage/util/*.java
Anyone have any ideas? Of course, to make matters worse, the reference I
normally use to deal with complex data types in CF has gone all 404:
http://hcc.musc.edu/research/shared_resources/xml_complex_types_to_cf_structure_
notes.cfm. If anyone knows of a good reference for this material, I'd love to
see it.
Thanks all,
insuractive - 29 May 2007 20:51 GMT
I've included some sample code below for the complex type (WSDL) and how I'm
calling it:
<!---================= WSDL SAMPLES =============------------------>
<!--- Webservice Method --->
<element name="miscGetMethod">
<complexType>
<sequence>
<element name="field1" nillable="true" type="xsd:string"/>
<element name="field2" nillable="true" type="xsd:string"/>
<element name="ihatethisfield" nillable="true"
type="impl:ArrayOf_xsd_nillable_string"/>
<element name="field4" nillable="true" type="xsd:string"/>
<element name="field5" nillable="true" type="xsd:string"/>
<element name="field6" nillable="true" type="xsd:string"/>
<element name="field7" nillable="true" type="xsd:string"/>
<element name="field8" type="xsd:boolean"/>
<element name="field9" type="xsd:boolean"/>
<element name="field10" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
<!--- Complex Type --->
<complexType name="ArrayOf_xsd_nillable_string">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="string"
nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<!---================= CF SAMPLE =============------------------>
<!--- My code --->
<cfset var stArgs = StructNew()>
<cfset var arrCodes = ArrayNew(1)>
<cfscript>
stArgs.field1 = "test";
stArgs.field2 = "test";
arrCodes[1] = "A";
arrCodes[2] = "B";
stArgs.ihatethisfield.string = arrCodes;
stArgs.field4 = "test";
stArgs.field5 = "test";
stArgs.field6 = "test";
stArgs.field7 = "test";
stArgs.field8 = "1";
stArgs.field9 = "0";
stArgs.field10 = "test";
</cfscript>
<cfinvoke webservice="#sWebserviceURL#"
method="miscGetMethod"
returnvariable="objResponse"
argumentcollection="#stArgs#"></cfinvoke>
insuractive - 30 May 2007 18:39 GMT
OK, so maybe some progress, maybe not. I've managed to retrieve the .java
files from the WSDL using C:\CFUSIONMX7\Runtime\Bin\wsdl2java.exe. This gave
me a directory tree that looked something like this:
com/companyName/division/domain
com/companyName/division/util
I used my Java IDE to compile the java files into class files (required the
appropriate jars:
C:/CFusionMX7/lib/axis.jar
C:/CFusionMX7/lib/xml-apis.jar
C:/CFusionMX7/lib/saaj.jar
C:/CFusionMX7/lib/jaxrpc.jar
I then placed my compiled classes (directory structure and all) in my
CFUSIONMX7/Lib directory and restarted the server.
I can now instantiate the custom Java class for the problem Web Service
parameter. Again, it works fine on my machine, but when I try to instantiate /
call the webservice on my STAGING server, I get the following error:
Could not instantiate stub objects for web service invocation.
The rootcause was that: java.lang.reflect.InvocationTargetException
Any Ideas?
insuractive - 31 May 2007 21:10 GMT
Well, after about a day and a half of troubleshooting, I finally figured out
how to get it to work. It seemed as if my last error had to do with the fact
that I had class files for the webservice objects scattered around my computer
and CF has having problems (name collisions, maybe?) creating the stub files it
needed for the web service invocation.
This, however, worked:
1) Update my machine to CF 7.0.2. so I don't have to keep uploading to the
staging server to test
2) After doing some more research in the following articles, it seemed as if
my initial approach (recreating complex object in CF structure/array) should
have worked:
http://phillhowson.com/blog/index.cfm/2006/9/1/ColdFusion-and-Web-Services
http://cfdj.sys-con.com/read/86131.htm
http://livedocs.adobe.com/coldfusion/6/Developing_ColdFusion_MX_Applications_wit
h_CFML/webservices6.htm
3) After playing around with syntax, I FINALLY found a solution that worked.
It wound up being as simple as:
stArgs.ihatethisfield= arrCodes;
(see my code above)
Now why the previous code worked in 7.0.0 and this syntax works in 7.0.2, I
have no idea.
But it works now, and that's all that matters.