How to migrate the New World Cruises application to JOnAS

 

The aim of this document is to show modifications of the J2EE application New World Cruise to migrate to JOnAS server

This document describes:

  1. JOnAS configuration.
  2. New World Cruise Application.
  3. SUN Web service.
  4. JOnAS Web service.

JOnAS configuration

First you must configure the database used for this application. For this copy under your directory $JONAS_BASE/conf the file <db>.properties. Then edit this file and complete the database connection.

You must also modify the file $JONAS_BASE/conf/jonas.properties on the part JOnAS DBM Database service configurations. Indeed, you must specify the file containing the database connection.

New World Cruise Application

EJB modification code

In order to be EJB2.0 compliant, you must add the exceptions RemoveException and CreateException for ejb's methods ejbRemove and ejbCreate.

Also, you must modify the GlueBean class, because in GlueBean constructor it uses a local object. But like it is a class calling an ejb, you must use a remote object, therefore modify the comment in this class for this modification.

   // If using the remote interface, the call would look like this
   cruiseManagerHome = (CruiseManagerHome)
        javax.rmi.PortableRemoteObject.narrow(result, CruiseManagerHome.class);
   // Using the local interface, so the call looks like this
   //cruiseManagerHome = (CruiseManagerHome) result;

EJB's Deployment descriptor

You have three ejb, so you must have three ejb-jar corresponding to ejb's deployment descriptor and 3 jonas-ejb-jar corresponding to jonas deployment descriptor.

First rename the files <ejb_name>.ejbdd by <ejb_name>.xml, this file contains the ejb deployment descriptor.

You must create the 3 file jonas-<ejb_name>.xml corresponding to those ejb.

For the two entity Bean (Cruise and CruiseManager), you must describe the mapping between :

- the ejb name and jndi name (jndi name =ejb/<ejb name>)

- the jdbc and the table name

- the ejb field and the table field because the version of CMP is not specify in ejb-jar and JOnAS use by default CMP1.1


For the session Bean, you must describe the mapping between :

- the ejb name and jndi name (jndi name =ejb/<ejb name>)

Web Application

Create the jonas-web.xml corresponding to the deployment descriptor of the New World Cruise application. Package in the war file the jonas-web.xml and the files accessible under the directory Cruises/cruise_WebModule.

Build Application

Build the ear corresponding to the application.

this ear contains the 3 files corresponding to the 3 ejb, and the web application.

SUN web service

Axis classes generation

First in order to call a web service you must generate axis classes. Those generate classes enable to call a web service using the static method.

For this step download the file AirService.wsdl corresponding to the SUN web service description or used the url containing this file.

Then use the command :

java org.apache.axis.wsdl.WSDL2java <file_name>

This command generates 4 java files :

* AirService.java : the service interface.

* AirServiceLocator.java : the service implementation.

* AirServiceServantInterface : the endpoint interface.

* AirServiceServantInterfaceBindingStub.java : the stub class.

To call the SUN web service you must instantiate the service implementation. Then apply the method getAirService() to get the end point, and apply the method.

 
        AirService airService=new AirServiceLocator();
        AirServiceServantInterface interface=airService.getAirService();
        Object result=interface.<method>;

JSP files

In the file Part2_site.zip, you have the web application which use the SUN web service.

Therefore, you have several jsp files. Those files must be modified to use the axis classes, those SUN files used its generated files, and you must use axis generated files.

For this replace for example in the index.jsp file

  // Get our port interface
  AirPack.AirClientGenClient.AirService service = 
            new AirPack.AirClientGenClient.AirService_Impl();
  AirPack.AirClientGenClient.AirServiceServantInterface port = 
            service.getAirServiceServantInterfacePort();

  // Get the stub and set it to save the HTTP log.
  AirPack.AirClientGenClient.AirServiceServantInterface_Stub stub = 
            (AirPack.AirClientGenClient.AirServiceServantInterface_Stub) port;
  java.io.ByteArrayOutputStream httpLog = 
               new java.io.ByteArrayOutputStream();
  stub._setTransportFactory
     (new com.sun.xml.rpc.client.http.HttpClientTransportFactory(httpLog));

  // Get the end point address and save it for the error page.
  String endPointAddress = (String) 
        stub._getProperty(stub.ENDPOINT_ADDRESS_PROPERTY);
  request.setAttribute("ENDPOINT_ADDRESS_PROPERTY", endPointAddress);

by

  // Get our port interface
  AirService_pkg.AirService service = new AirService_pkg.AirServiceLocator();
  AirService_pkg.AirServiceServantInterface port = 
           service.getAirServiceServantInterfacePort();

Also the Exception :

throw new com.sun.xml.rpc.client.ClientTransportException(null, new Object[] {e}); 

is replaced by

 throw new Exception(e);

Web Application

Finally, you can create the web application and reuse web.xml existing in Part2_site.zip. For this create the jonas-web.xml. Then build the web application which contains :

    META-INF/
    META-INF/MANIFEST.MF
    WEB-INF/
    WEB-INF/jonas-web.xml
    WEB-INF/lib/
    WEB-INF/lib/CruiseManager.jar
    WEB-INF/classes/
    WEB-INF/classes/AirService_pkg/
    WEB-INF/classes/AirService_pkg/AirServiceServantInterface.class
    WEB-INF/classes/AirService_pkg/AirServiceServantInterfaceBindingStub.class
    WEB-INF/classes/AirService_pkg/AirService.class
    WEB-INF/classes/AirService_pkg/AirServiceLocator.class
    PalmTree.jpg
    aboutus.jsp
    air_icon.gif
    airbook.jsp
    airclient.jsp
    airdates.jsp
    airdone.jsp
    airlist.jsp
    clear.gif
    crubook.jsp
    crudone.jsp
    cruise_icon.gif
    cruises.jsp
    flights.jsp
    index.jsp
    nwcl_banner.gif
    nwcl_banner_a.gif
    nwcl_styles.css
    WEB-INF/web.xml

JOnAS web service

Deployment

This web service use the EJB stateless CruiseManager. To deploy this web service you must create the web service deployment descriptor :

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

    <!-- 
        AXIS deployment file for EJB Cruise
    -->
     <service name="AirService" provider="java:EJB">
     
        <!--
            JNDI name specified in jonas-CruiseApp.xml
        -->
        <parameter name="beanJndiName"          
                        value="ejb/CruiseManager"/>

        <!--
            use of remote interfaces to acces the EJB is allowed
        -->
          <parameter name="homeInterfaceName"   
                        value="cruisePack.CruiseManagerHome"/>
          <parameter name="remoteInterfaceName" 
                        value="cruisePack.CruiseManager"/>


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

        <typeMapping
            xmlns:ns="urn:AirService/types"
            qname="ns:ArrayOfString"
            type="java:java.lang.String[]"
            serializer="org.apache.axis.encoding.ser.ArraySerializerFactory"
            deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        />
    </service>
  </deployment>

To deploy this web service you must deploy first the web application axis.war,and the ejb corresponding to the web service (CruiseManager.jar).

The using the axis client deploy the web service :

    jclient org.apache.axis.client.AdminClient 
               -lhttp://localhost:<port>/<context-root-axis.war>/servlet/AxisServlet <ws_wsdd>

Axis classes generation

First in order to call a web service you must generate axis classes. Those generate classes enable to call a web service using the static method.

For this step download the file AirService.wsdl corresponding to the SUN web service description or used the url containing this file.

The use of the command :

java org.apache.axis.wsdl.WSDL2java <file_name or url>

This command generates 4 java files :

* CruiseManagerService.java : the service interface.

* CruiseManagerServiceLocator.java : the service implementation.

* CruiseManager.java : the endpoint interface.

* AirServiceSoapBindingStub.java : the stub class.

To call the JOnAS web service you must instantiate the service implementation. Then apply the method getAirService() to get the end point interface, and apply the method.

 
       AirService_JOnAS.Client.CruiseManagerService cms=
            new AirService_JOnAS.Client.CruiseManagerServiceLocator();

       AirService_JOnAS.Client.CruiseManager cmi=cms.getAirService();

       Object result=cmi.<method>;

JSP files

To access to JOnAS web service copy the jsp files containing in the EJB's web application (Cruises/cruise_WebModule).

Each EJB's call must be replaced by the JOnAS web service call.

Web Application

Finally, you can create the web application. For this create the jonas-web.xml. Then build the web application which contains :

    META-INF/
    META-INF/MANIFEST.MF
    WEB-INF/
    WEB-INF/jonas-web.xml
    WEB-INF/lib/
    WEB-INF/lib/CruiseManager.jar
    WEB-INF/classes/
    WEB-INF/classes/AirService_pkg/
    WEB-INF/classes/AirService_JOnAS/Client/CruiseManagerService.class
    WEB-INF/classes/AirService_JOnAS/Client/AirServiceSoapBindingStub.class
    WEB-INF/classes/AirService_JOnAS/Client/CruiseManager.class
    WEB-INF/classes/AirService_JOnAS/Client/CruiseManagerServiceLocator/AirServiceLocator.class
    PalmTree.jpg
    aboutus.jsp
    air_icon.gif
    airbook.jsp
    airclient.jsp
    airdates.jsp
    airdone.jsp
    airlist.jsp
    clear.gif
    crubook.jsp
    crudone.jsp
    cruise_icon.gif
    cruises.jsp
    flights.jsp
    index.jsp
    nwcl_banner.gif
    nwcl_banner_a.gif
    nwcl_styles.css
    WEB-INF/web.xml