# Howto: Web Service Interoperability between JOnAS and Weblogic

This guide describes the basic use of web services between JOnAS and Weblogic server. It assumes that the reader does not require any explanation about Axis-specific tasks (axis deployment with WSDD, etc.).

This document describes the following two aspects:

1. Access a web service deployed on JOnAS from an EJB deployed on Weblogic server.
2. Access a web service deployed on Weblogic server from an EJB deployed on JOnAS.

## Libraries

JOnAS incorporates all the necessary libraries, including:

- JAX-R: Reference Implementation from Sun
- JAX-M: Reference Implementation from Sun
- JAX-P: Xerces XML parser (version 2.4.0)
- AXIS: Soap implementation from Apache (with all dependent libs: jaxrpc.jar, etc.)

(JAX-M and JAX-R are parts of the Web Services Development Pack from Sun.)

Weblogic incorporates all the necessary libraries, including:

- All libraries for using webservice are contained in webserviceclient.jar.

## Access a web service deployed on JOnAS from an EJB deployed on Weblogic server

### Web Service Development on JOnAS

Also refer to the document How to use Axis with JOnAS, which describes how to develop and deploy web services on JOnAS.

#### 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.

#### 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"/>`

`<!-- 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.SerializerFactory" 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.SerializerFactory, and the deserializer used is my.java.DeserializerFactory.

#### 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
Note: from JOnAS 3.3, jclient no more include WebServices libraries in the CLASSPATH. So you have to manually add this jar in your CLASSPATH:
export CLASSPATH=$CLASSPATH:$JONAS_ROOT/lib/webservices_axis.jar

The web service WSDL is accessible from the url: http://<host>:<port>/<url-servlet>/<webservicename>?wsdl.

### EJB proxy development for Weblogic Server

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

#### 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" keepGenerated="True"/>

This command creates four classes:

- Service implementation
- Java Interface
- Stub class
- Service interface corresponding web service

The tool can also generate the java classes corresponding to future complex types of web service.

#### Build the EJB

Then, call the web service in the EJB proxy code using these 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);
                 };

#### Deploy the EJB on Weblogic Server

Deploy this EJB using the weblogic administration console.

## Access a web service deployed on Weblogic server from an EJB deployed on JOnAS

### Web Service Development for Weblogic Server

#### 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>

THE ANT USED IS PROVIDED BY WEBLOGIC

#### 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.

### EJB proxy development for JOnAS

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

#### 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 corresponding web service

The tool also generates the java class corresponding to future complex types of web service.

#### 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);
                };

#### Deploy the EJB on JOnAS

Deploy the EJB using the JOnAS administration console or command.