10.5 Wrapping J2EE and JRun Web Services

Accessing a remote web service from a Java application server or JRun 4 is a little more complicated than utilizing a web service from ColdFusion MX or ASP.NET. You need to manually create the proxy for the web service, using some tools that are readily available and preinstalled as part of the JRun 4 installation.

JRun 4 comes with a command-line tool called wsdl2java.exe (located in the Jrun4\bin directory), which is part of the Apache Axis implementation of SOAP. If you are using an alternate J2EE server, you can download the necessary components from http://xml.apache.org/axis. The wsdl2java tool from the Apache web site is a Java .jar file rather than a command-line program. More information on the classes can be found at http://xml.apache.org/axis.

The wsdl2java tool automatically creates most of the Java code necessary to consume the web service from Flash. It transforms a .wsdl file into a Java interface. You can use wsdl2java manually from a command line. To convert the Whois service shown earlier, navigate to the directory containing the wsdl2java.exe file and run it as follows:

wsdl2java -o yourSourceDir http://www.soapclient.com/xml/SQLDataSoap.wsdl

Using the .jar version of wsdl2java, you call it like this:

java org.apache.axis.wsdl.WSDL2Java
http://www.soapclient.com/xml/SQLDataSoap.wsdl -o yourSourceDir

If you are using the wsdl2java.jar file from the Apache site, make sure you include the following classes in your classpath when running the tool:

  • axis_directory/lib/axis.jar

  • axis_directory/lib/jaxrpc.jar

  • axis_directory/lib/saaj.jar

  • axis_directory/lib/commons-logging.jar

  • axis_directory/lib/commons-dicovery.jar

  • axis_directory/lib/wsdl4j.jar

  • An XML parser, such as Xerces

The wsdl2java conversion tool creates at least four .java stub and skeleton files in the classes\com\SoapClient\www directory, using the o switch to specify the output directory. Each web service has its own directory structure, based on the domain name of the service. These four files for this particular web service are:

SQLDataSoap.java
SQLDataSoapBindingStub.java
SQLDataSoapLocator.java
SQLDataSoapPortType.java

These Java source files need to be compiled. The packages needed by these stub and skeleton files are all included in jrun_directory/lib/webservices.jar for JRun 4. To utilize the classes from Flash Remoting, you have to create a wrapper JavaBean. The Java code shown in Example 10-3 acts as a wrapper bean for this particular web service. It can be easily modified to work with any web service.

Example 10-3. JavaBean wrapper code for the Whois web service
// Use the same package as the wsdl2java-generated classes
package com.SoapClient.www;

// Handle to the generated stub
public class SQLDataSoapBean {
  private com.SoapClient.www.SQLDataSoapBindingStub soap;

  // Empty constuctor
  public SQLDataSoapBean( ) throws java.net.MalformedURLException,
   org.apache.axis.AxisFault {
     final java.net.URL endPoint =
      new java.net.URL("http://www.SoapClient.com/xml/SQLDataSoap.wsdl");
     soap = new com.SoapClient.www.SQLDataSoapBindingStub(endPoint,
            new org.apache.axis.client.Service( ));
  }

  // Public method to call the web services method processSRL
  public String processSRL(String SRLFile, String requestName,
   String key) throws java.rmi.RemoteException {
    return soap.processSRL(SRLFile, requestName, key);
  }
}

After compiling the stub, skeleton, and JavaBean files, you should be able to use the Flash code shown in Example 10-1, changing the service path to the path of your JavaBean. When accessing a web service through a J2EE server, you don't access the service directly, as you would with a ColdFusion or ASP.NET server, but instead access the wrapper that you just created:

var servicePath = "com.SoapClient.www.SQLDataSoapBean";

As you can see, using web services from J2EE servers is slightly more complex than it is from ColdFusion or ASP.NET, but once you've consumed one service, you can easily adapt the code to consume other services.



    Part III: Advanced Flash Remoting
     
    ASPTreeView.com
     
    Evaluation has СµМexpired.
    Info...