Accessibility

TechNote (Archived)

Creating webservice stubs with wsdl2java in ColdFusion MX 7

Issue


ColdFusion MX automatically creates webservices stubs when usingcfinvoke, cfobject, orcreateObject() to call webservices and when registering webservices in the CF Administrator. Webservice stubs are Java classes that ColdFusion MX uses to communicate with the webservice. ColdFusion uses the wsdl2java utility, included as part of Apache Axis, to create these stubs. Once created, these stubs are stored under the cf_root/stubs directory.

There are times when it is useful to run the wsdl2java utility manually. For example, you may need to examine the stub source code in order to understand what is needed to successfully invoke a complex webservice. Furthermore, you may need to instantiate Java objects within the stub classes in order to populate the input arguments required by a webservice method.

Solution


While it is possible to use the wsdl2java.exe that is included as part of JRun, this is not recommended because it will use the version of Axis that ships with JRun. If you are troubleshooting a ColdFusion problem, it is better to call wsdl2java.jar directly and use the Axis classes that are included with ColdFusion MX. You must include several JAR files in your classpath as shown in the following examples. (Unlike ColdFusion MX 6, ColdFusion MX 7 does not include its own version of webservices.jar.)

Standalone ColdFusion MX 7:

set CFLIB=c:/CFusionMX7/lib
set CLASSPATH=%CFlib%/axis.jar;%CFlib%/jaxrpc.jar;%CFlib%/saaj.jar;%CFlib%/commons-logging-1.0.2.jar;%CFLIB%/commons-logging-api-1.0.2.jar;%CFlib%/commons-discovery-0.2.jar;%CFlib%/wsdl4j-1.5.1.jar;%CFLIB%/xml-apis.jar;%CFLIB%/xercesImpl.jar;%CFLib%/../runtime/lib/jrun.jar

C:\j2sdk1.4.2_10\bin\java -cp %CLASSPATH% org.apache.axis.wsdl.WSDL2Java -o c:\path\to\output\directory -v http://path/to/wsdl/file.wsdl

J2EE configuration on JRun:

set CFlib=C:/JRun4/servers/CFMX702/cfusion-ear/cfusion-war/WEB-INF/cfusion/lib
set CLASSPATH=%CFlib%/axis.jar;%CFlib%/jaxrpc.jar;%CFlib%/saaj.jar;%CFlib%/commons-logging-1.0.2.jar;%CFLIB%/commons-logging-api-1.0.2.jar;%CFlib%/commons-discovery-0.2.jar;%CFlib%/wsdl4j-1.5.1.jar;%CFLIB%/xml-apis.jar;%CFLIB%/xercesImpl.jar;c:/Jrun4/lib/jrun.jar

C:\j2sdk1.4.2_10\bin\java -cp %CLASSPATH% org.apache.axis.wsdl.WSDL2Java -o c:\path\to\output\directory -v http://path/to/wsdl/file.wsdl

J2EE configuration on Websphere:

set CFlib="C:\Program Files\WebSphere\AppServer\installedApps\dstanten-D380Network\Macromedia ColdFusion MX.ear\cfusion.war\WEB-INF\cfusion\lib"

set CLASSPATH=%CFlib%/axis.jar;%CFlib%/jaxrpc.jar;%CFlib%/saaj.jar;%CFlib%/commons-logging-1.0.2.jar;%CFLIB%/commons-logging-api-1.0.2.jar;%CFlib%/commons-discovery-0.2.jar;%CFlib%/wsdl4j-1.5.1.jar;%CFLIB%/xml-apis.jar;%CFLIB%/xercesImpl.jar;%CFlib%/mail.jar;C:/Products/jdk/activation.jar

C:\j2sdk1.4.2_10\bin\java -cp %CLASSPATH% org.apache.axis.wsdl.WSDL2Java -o c:\path\to\output\directory -v http://path/to/wsdl/file.wsdl

Notes:
The -o switch is used to specify the directory where you want the stubs saved. The -v switch can be used to provide verbose output. You provide the path to a WSDL file as the final argument. This can either be in the form of a URL, or you can specify the path to a WSDL file on disk.

Check the names of these JAR files against the JAR in your CFlib directory. Some of the JAR names may include version numbers that may change slightly depending on the exact version of ColdFusion MX 7 you have installed.

Activation.jar is needed when running ColdFusin MX on J2EE servers other than JRun. Activation.jar can be downloaded from Sun's Java Activation Framework web site. If you do not include activation.jar, you will see the following error, although the stubs may still get generated:

 "0 [main] WARN utils.JavaUtils - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled." 
Compiling:

To compile the stubs created by wsdl2java, you need to add the same JAR files to your classpath as when running wsdl2java. For example:

set CFLIB=c:/CFusionMX7/lib
set CLASSPATH=%CFlib%/axis.jar;%CFlib%/jaxrpc.jar;%CFlib%/saaj.jar;%CFlib%/commons-logging-1.0.2.jar;%CFLIB%/commons-logging-api-1.0.2.jar;%CFlib%/commons-discovery-0.2.jar;%CFlib%/wsdl4j-1.5.1.jar;%CFLIB%/xml-apis.jar;%CFLIB%/xercesImpl.jar;%CFLib%/../runtime/lib/jrun.jar

C:\j2sdk1.4.2_10\bin\javac -classpath %CLASSPATH% path/to/stub/source/*.java -verbose

Additional Information


JRun LiveDocs on wsdl2java

Axis user's guide

Creating webservice stubs with wsdl2java in ColdFusion MX 6.1 (TechNote ea87b65)

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:eaf0396

Products Affected:

coldfusion