36.3. Accessing a WebLogic Web Service from a JOnAS EJB

36.3.1. Web Service Development for WebLogic Server

36.3.1.1. Creation of an Application

To create a web service, first develop the corresponding EJB application. Compile the EJB classes and create a JAR file. To create the EJB's container, apply the ant task
wlappc
to the JAR file. For example:

<wlappc debug="${debug}" source="interface_ws_jonas.jar"
    classpath="{java.class.path}:interface_ws_jonas.jar"

Then, use the ant task servicegen to create the ear application containing the web service.

           
<servicegen 
  destEar="ears/myWebService.ear" 
  contextURI="web_services" > 
  <service 
    ejbJar="jars/myEJB.jar" 
    targetNamespace="http://www.bea.com/examples/Trader" 
    serviceName="TraderService" 
    serviceURI="/TraderService" 
    generateTypes="True" 
    expandMethods="True" > 
  </service> 
</servicegen> 

Use the version of ant provided with WebLogic Server.

36.3.1.2. WebService Deployment

Deploy the webservice using the WebLogic administration console, and deploy the corresponding application.

The WSDL is accessible at http://host:port/webservice/web_services?WSDL

36.3.2. EJB Proxy Development for JOnAS

This EJB provides access to the web service deployed on WebLogic from JOnAS.

36.3.2.1. Generation of Web Service Client Class

To access a web service, generate a client class using the Axis tool WSDL2Java <webservice-url-wsdl>. This command creates four classes:

  • WSNAME_Locator.java: Service implementation

  • WSNAME_Port.java: Java Interface

  • WSNAME_PortStub.java: Stub class

  • WSNAME.java: Service interface to the corresponding web service.

The tool can also generate the Java classes corresponding to future complex types of web services.

36.3.2.2. Build the EJB

Then, use this generated class to call the web service in the EJB proxy code. For example:

try {
    WSNAMELocator tsl=new WSNAMELocator();
    WSNAMEPort tsp = tsl.getWSNAMEPort();
    ComplexType tr=tsp.method(param);
    ...
    } catch (Exception e) {
         e.printStackTrace(System.err);
    };

36.3.2.3. Deploy the EJB on JOnAS

Deploy the EJB using the JOnAS administration console or command.