Howto: Migrate the New World Cruises application to JOnAS

 

This guide describes the modifications required for migrating the J2EE application New World Cruise to JOnAS server.

The content of this guide is the following:

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

JOnAS configuration

The first step is to configure the database used for this application. Copy the file <db>.properties to the directory $JONAS_BASE/conf. Edit this file to complete the database connection.

Then, modify the JOnAS DBM Database service configurations in the file $JONAS_BASE/conf/jonas.properties, to specify the file containing the database connection.

New World Cruise Application

EJB modification code

To be EJB2.0-compliant, add the exceptions RemoveException and CreateException for EJB's methods ejbRemove and ejbCreate.

Additionally, the GlueBean class uses a local object in GlueBean constructor. However, it must use a remote object because it is a class calling an EJB. Therefore, modify the comment in this class with the following:

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

EJB's Deployment descriptor

There are three EJBs, thus there must be three ejb-jar.xml files that correspond to the EJB's deployment descriptors and three jonas-ejb-jar.xml files that correspond to the JOnAS deployment descriptors.

First, rename the files <ejb_name>.ejbdd with <ejb_name>.xml; these files contain the EJB deployment descriptors.

Create the three jonas-<ejb_name>.xml files corresponding to the EJBs.

For the two entity Beans (Cruise and CruiseManager), 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, (the version of CMP is not specify in ejb-jar and JOnAS by default uses CMP1.1).


For the session Bean, describe the mapping between:

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

Web Application

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

Build Application

Build the ear corresponding to the application.

This ear contains the three files corresponding to the three EJBs, as well as the web application.

SUN web service

Axis classes generation

To call a web service, first generate axis classes. The generated classes will allow a web service to be called using the static method.

For this step, download the file AirService.wsdl that corresponds to the SUN web service description or use the URL containing this file.

Then use the command:

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

This command generates four 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, instantiate the service implementation. Then call the method getAirService() to get the end point, and call the appropriate method.

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

JSP files

The file Part2_site.zip contains the web application that uses the SUN web service.

It includes several jsp files that must be modified to use the axis classes.

As an example, make the following replacements 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();

Additionally, the Exception

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

is replaced by

 throw new Exception(e);.

Web Application

Finally, create the web application (jonas-web.xml) and reuse the web.xml that is in Part2_site.zip. 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 uses the EJB stateless CruiseManager. To deploy this web service, 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 access 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, first deploy the web application axis.war and the EJB corresponding to the web service (CruiseManager.jar).

Then, deploy the web service using the axis client:

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

Axis classes generation

To call a web service, first generate axis classes. The generated classes will allow a web service to be called using the static method.

For this step, download the file AirService.wsdl corresponding to the SUN web service description or use the URL containing this file.

The use of the command is as follows:

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

This command generates four 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, instantiate the service implementation. Then, call the method getAirService() to get the end point interface, and call the appropriate 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 the JOnAS web service, copy the jsp files contained in the EJB's web application (Cruises/cruise_WebModule).

The JOnAS web service call must replace the call for each EJB.

Web Application

Finally, create the web application: 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