36.2. Accessing a JOnAS Web Service from a WebLogic Server's EJB

36.2.1. Web Service Development on JOnAS

Refer to Chapter 34 How to use Axis in JOnAS, which describes how to develop and deploy web services on JOnAS.

36.2.1.1. EJB Creation on JOnAS

To create a web service based on an EJB, first create a stateless EJB. Then, create a web application (.war) or an application (.ear) with this EJB that will define a URL with access to the Web Service.

36.2.1.2. WebService Deployment Descriptor (WSDD)

This section describes the deployment descriptor of the web service. To deploy a web service based on an EJB, specify the various elements in the WSDD. This WSDD enables the web service to be mapped on an EJB, by specifying the different EJB classes used.

<deployment xmlns="http://xml.apache.org/axis/wsdd/" 
   xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<!-- AXIS deployment file for HelloBeanService --> 
    <service name="WebServiceName" provider="java:EJB">

<!-- JNDI name specified in jonas-EJB.xml --> 
    <parameter name="beanJndiName" value="EJB_JNDI_Name"/>

<!-- use of remote interfaces to access the EJB is allowed, but this
    example uses local interfaces --> 
    <parameter name="homeInterfaceName" value="EJB_Home"/> 

<parameter name="remoteInterfaceName" value="EJB_Interface"/>

<!-- JNDI properties: it may be necessary to modify hostname and port
    number, protocol name could be changed in accordance with the ORB 
    used -->

<!-- for a RMI ORB --> 
    <parameter name="jndiURL" value="rmi://<url>:<port>"/>

<parameter name="jndiContextClass" 
    value="com.sun.jndi.rmi.registry.RegistryContextFactory"/>

<!-- Specify here allowed methods for Web Service access (* for all) --> 
    <parameter name="allowedMethods" value="*"/>

    </service>
</deployment>

The various tags allow mapping of the web service on different java classes. If a web service uses a complex type, this complex type must be mapped with a java class. To do this, two tags can be used:

<beanMapping qName="ns:local" xmlns:ns="someNameSpace"
languageSpecificType="java:my.class"/>

This maps the QName [someNameSpace]:[local] with the class my.class.

<typeMapping qname="ns:local" wmlns:ns="someNamespace"
languageSpecificType="java:my.class" serializer="my.java.Serializer"
deserializer="my.java.DeserializerFactory"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

where QName [someNameSpace]:[local] is mapped with my.class. The serializer used is the class my.java.Serializer and the deserializer used is my.java.DeserializerFactory.

36.2.1.3. Web Service Deployment on JOnAS

First, deploy the web application or the application containing the EJB. Then, deploy the web service using the Axis client tool:

jclient org.apache.axis.client.AdminClient 
   -hjonasServerHostname -p9000 deploy.wsdd

The web service WSDL is accessible from the url:

http://host:port/url-servlet/webservicename?wsdl.

36.2.2. EJB Proxy Development for WebLogic Server

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

36.2.2.1. Generation of Web Service Client Class

To access the web service, generate the client class using the Ant task clientgen. For example:

<clientgen wsdl="<wsdl_url>" packageName="my.package"
   clientJar="client.jar" generatePublicFields="True"
   keep generated="True"/>

This command creates four classes:

  • Service implementation

  • Java interface

  • Stub class

  • Service interface to the corresponding web service.

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

36.2.2.2. Build the EJB

Then, call the web service in the EJB proxy code using the generated classes. For example:

try {
       WSNAME_Impl tsl=new WSNAME_Impl(); // access web service impl
       EJB_endpoint tsp = tsl.getEJB_endpoint(); 
         // access WS endpoint interface
       ComplexType tr=tsp.method(param);
    }  catch (Exception e) {
       e.printStackTrace(System.err);
    };

36.2.2.3. Deploy the EJB on WebLogic Server

Deploy this EJB using the WebLogic administration console.