Sun Java System logo      Previous      Contents      Next     
CORBA Interoperability Sample Application



Servlets Accessing Backend CORBA Objects via IONA Orbix


This document describes how to utilize the CORBA Interoperability sample application in conjunction with Sun Java (tm) System Application Server version 7.

This sample application document contains the following sections:



Overview

This example application demonstrates how a very simple servlet can call methods of a remote CORBA object based on using Orbix as the underlying

ORB. Since the servlet accesses the "SimpleObject" CORBA object that is part of the Orbix demo applications, you must first ensure that you've run the Orbix demo application in the Orbix environment, before running this Sun Java (tm) System sample application.

Initialization of multiple ORBs in this sample is avoided through the use of a singleton class. Regardless of the number of instances of the Servlet created by the Servlet container, the singleton approach ensures that at most one instance of the ORB is created for the entire application. To learn more about how the singleton design pattern has been used in this sample, review the Using a Singleton for ORB Initialization document.

Figure 3 depicts the main components of this sample:



Figure 3    CORBA sample stucture


Setting Up the Environmentl

Setting up third party ORBs in Sun Java (tm) System Application Server describes how to setup and run the Orbix "SimpleObject" demo application in a standalone mode prior to following the instructions to run it with Sun Java (tm) System Application Server. Refer to the E2A Application Server Platform 5.1 Configuration document for more infomration.



Compiling and Assembling the Application



Although the pre-built XML deployment descriptors are included with the sample, includes preset values of environment setting, these values may not match your ORB installation path. The first step in assembling the sample is to modify the environment settings.

There are two locations where you have to modify the settings as per your ORB installation:

After changing the environment settings , go to Compiling and Assembling the Application Using Ant Build Facility. The fastest means of setting up the application is to use the Command Line Interface (CLI)-based Deployment. If you would like to deploy through Admin GUI, then follow instructions for Web Interface (GUI)-based Deployment.


Modifying web.xml CORBA Environment Settings

The sample web application relies on several J2EE environment settings to access the Orbix ORB domain location and several Interoperable Object Reference (IOR) files. Preset values are included in the pre-built EAR, but these default values are unlikely to suit your ORB installation path. (Since this is a 'simple' sample, IOR files are used in place of dynamic lookups through a CORBA naming service).

Table 2 lists the environment settings required by the sample web application. These settings are available in the web.xml file, which is under the src/ directory of the sample application. If you are using the Ant Build facility to rebuild the sample application, then you can simply change the settings as they appear in the web.xml file and rebuild the application.


Table 2    Required Environment Settings

Environment Name

Description

orbDomainName  

Name of ORB domain.  

orbCfgDir  

Location of domain configuration file.  

simpleObjectIor1  

IOR file used to access first CORBA object. Produced when the Orbix sample build script is executed.  

simpleObjectIor2  

IOR file used to access second CORBA object. Produced when the Orbix sample build script is executed.

 

Modifying these settings in the web.xml file is preferred because the changes will be present each time you deploy the application to the application server.

To modify the environment setting in the web.xml file, do the following:

  1. Edit <Sun-Java-System-AS-install_dir>/samples/corba/servletsample/src/web.xml

  2. Change the environment settings listed in Table 2 to match your ORB installation:

    • On Windows:

      ...

      <env-entry>

      <env-entry-name>orbCfgDir</env-entry-name>

      <env-entry-value>c:\<domain_path>\domains</env-entry-value>

      <env-entry-type>java.lang.String</env-entry-type>

      </env-entry>

      <env-entry>

      <env-entry-name>simpleObjectIor1</env-entry-name>

      <env-entry-value>c:\<orb_installpath>\demos\corba\orb\simple1.ior</env-entry-value>

      <env-entry-type>java.lang.String</env-entry-type>

      </env-entry>

      <env-entry>

      <env-entry-name>simpleObjectIor2</env-entry-name>

      <env-entry-value>c:\<orb_installpath>\demos\corba\orb\simple2.ior</env-entry-value>

      <env-entry-type>java.lang.String</env-entry-type>

      </env-entry>

      ...

    • On Solaris:

      ...

      <env-entry>

      <env-entry-name>orbCfgDir</env-entry-name>

      <env-entry-value>/<domain_path>/domains</env-entry-value>

      <env-entry-type>java.lang.String</env-entry-type>

      </env-entry>

      <env-entry>

      <env-entry-name>simpleObjectIor1</env-entry-name>

      <env-entry-value>/<orb_installpath>/demos/corba/orb/simple1.ior</env-entry-value>

      <env-entry-type>java.lang.String</env-entry-type>

      </env-entry>

      <env-entry>

      <env-entry-name>simpleObjectIor2</env-entry-name>

      <env-entry-value>/<orb_installpath>/demos/corba/orb/simple2.ior</env-entry-value>

      <env-entry-type>java.lang.String</env-entry-type>

      </env-entry>

      ...


Modifying The Build File

Before recompilation and reassembling the sample, you will need to modify the build file to reflect the installation location of your ORB.

  1. Under the directory <Sun-Java-System-AS-install_dir>/samples/corba/servletsample/src/

  2. Edit the build.xml file by modifying the following property to suit your ORB installation environment:

    On Windows:

    <!-- OMG CORBA Classes -->

    <property name="orb.installpath" value="<orb_installpath"/>

    On Solaris:

    <!-- OMG CORBA Classes -->

    <property name="orb.installpath" value="<orb_installpath>"/>

These modifications will enable you to easily compile and reassemble the sample application. If you don't make this change, the servlet source code will not compile because it will not be able to access the OMG ORB classes.


Compiling and Assembling the Application Using Ant Build Facility

To compile and assemble the application using Ant Build Facility, do the following:

  • On UNIX, prior to executing the build command, you need to ensure that <Sun-Java-System-AS-install_dir>/bin is in your PATH.

  • Rebuild the application by executing the asant command under the <Sun-Java-System-AS-install_dir>/samples/corba/servletsample/src/ directory. For example:

    asant

Executing the build command will compile the application source files and reassemble both the WAR and EAR files. The EAR file will be placed in <Sun-Java-System-AS-install_dir>/samples/corba/servletsample/assemble/ear/.

You are now ready to follow either the Command Line Interface (CLI)-based Deployment or Web Interface (GUI)-based Deployment instructions.



Deploying the Sample



After compiling and assembling the application, you can choose to deploy and register the application through either command line utilities or Sun Java (tm) System Application Server Admin GUI. The deployment procedure is same for Windows and Solaris platforms.


Command Line Interface (CLI)-based Deployment

Once you've modified the CORBA environment settings, deploying the newly built corba-servletsample.ear file is simple.

  1. Go to the directory in which the newly assembled EAR file is located. For example: <Sun-Java-System-AS-install_dir>/samples/corba/servletsample/assemble/ear

  2. Before executing the command line deploy utility, ensure that you have <Sun-Java-System-AS-install_dir>/bin in your PATH.

  3. Execute iasadmin to deploy application to the particular application server instance. For example:

    asadmin deploy --type application --instance <instance name> --host <hostname.domainname> --port <admin port>

    --user <admin user> --password <admin pass> --name <app root name> --force=true corba-servletsample.ear

  4. Alternatively, under the src/ directory, you can execute following command to deploy the application to the default application server instance installed on localhost.

    asant deploy

If you would like to verify the registration of the application, proceed to Verifying Registration. Otherwise, you're ready to exercise the application by Running the Sample Application.


Web Interface (GUI)-based Deployment

The Sun Java (tm) System Admininstration Tool GUI provides an easy way of deploying applications to Sun Java (tm) System Application Server.


Note Before proceeding, you must ensure that the application is repackaged with modified deployment descriptors containing the environment setting in accordance with your ORB installation.



Since a prebuilt Enterprise Archive (EAR) file for the sample application is included with the application server, you can deploy it to the application server if your ORB installation is set to default or first build the application using Ant Build Facility and use this EAR file for deployment.

  1. Open the browser and go to the admin server. For example:

    http://<host>:<admin port>/

  2. Login as Admin user.

  3. Go to Application Server Instances -> server1 (or any other instance) -> Applications

    Click on the link Enterprise Applications.

    You will see the deployed j2ee applications on this server instance here.

  4. Click on the Deploy tab to deploy your application.

  5. Give the absolute location of your Application EAR file

    or

    Navigate to <Sun-Java-System-AS-install_dir>/samples/corba/ejb/assemble/ear and open the corba-servletsample.ear file.

  6. Click OK.

  7. After uploading your application EAR file, the GUI will ask you for a AppName.

    Type any appropriate AppRoot directory name and click OK.

If you have deployed the application successfully, this application will be listed under Deployed Applications. After the application is deployed you can proceed to Running the Sample Application.


Verifying Registration

To verify the registration of the application, do the following:

  1. In the Admin GUI go to Application Server Instances -> server1 (or any other instance) -> Applications.

  2. Click on the link Enterprise Applications.

    You will see the deployed j2ee applications on this server instance.

  3. You can also execute the asadmin command to look at applications deployed with a server instance. For example:

    asadmin list-components -u <username> -w<password> -H <host> -p <admin-port><server instance name>



Running the Sample Application

Prior to running the sample, ensure that you have performed the following steps:

  1. Run the Orbix SimpleObject sample in standalone mode outside of Sun Java (tm) System Application Server.

  2. Started the server side CORBA object.

Refer to the E2A Application Server Platform 5.1 Configuration to see how to setup and run the Orbix "SimpleObject" demo application in a standalone mode prior to running the servlet application in the application server.

  1. After you've started the Orbix services and the server side CORBA object, run the application by accessing:

    http://<application server hostname>:<instance http port>/corba-servletsample/CorbaClientServlet

You should see the following output in your browser:



Figure 4    Servlet accessing backend CORBA server



Troubleshooting



Although the sample web application contains limited exception handling, it should provide you with a sense of some of the failure scenarios and basic recovery techniques that apply when accessing remote CORBA objects from within the application server.


Servlet Initialization Failures

Servlet may issue a ServletException during the servlet's init() method due to any one of the following actions:

  • By not including the Orbix classes in the application server's CLASSPATH

  • By renaming or deleting one or more of the environment settings contained in the web application

  • By renaming one of the IOR files

  • By not starting the Orbix services


Post Initialization Failures

If you stop the server side CORBA object server and rerun the servlet application, you will notice that the servlet will catch the CORBA exceptions and attempt to reinitialize object references. These attempts will fail until you restart the CORBA object server.

Upon restarting the CORBA object server and attempting to rerun the servlet application, you should observe that the client successfully reinitializes the object references and access the remote methods.


Run time errors

Ensure that you've started the Orbix services as well as the CORBA server prior to running the application.

The following errors are described in this section:


CORBA.OBJ_ADAPTER Error

If you encounter the following messages in the Server log file, then you have not configured the application server to use the Orbix ORB classes. Refer to the E2A Application Server Platform 5.1 Configuration document for more details.

Browser output:

Invoking method on first object.

Caught exception: org.omg.CORBA.OBJ_ADAPTER: vmcid: SUN minor code: 202 completed: No (Minor code meaning not found)Server log:

Server Log:

[16/Apr/2002:19:13:15] INFO (10660): CorbaClientServlet: Invoking method on first object.

[16/Apr/2002:19:13:15] INFO (10660): creating connection to EndPoint: EndPoint

[IIOP_CLEAR_TEXT:129.158.228.203:38717:false]

[16/Apr/2002:19:13:15] INFO (10660): Caught exception: org.omg.CORBA.OBJ_ADAPTER: vmcid: SUN minor code: 202 completed: No (Minor code meaning not found)


NoClassDefFoundError

If you encounter the following messages in the Server log file, then you have not configured the application server to use the Orbix ORB classes. Refer to the E2A Application Server Platform 5.1 Configuration document for more details.

Browser output:

exception

javax.servlet.ServletException: Servlet.init() for servlet CorbaClientServlet threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrappe r.java:935) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.j ava:653)

...

root cause

java.lang.NoClassDefFoundError: com/iona/corba/util/SystemExceptionDisplayHelper at samples.corba.common.OrbSingleton.(OrbSingleton.java:40) at samples.corba.common.OrbSingleton.getInstance(OrbSingleton.java:51)

...

Server log:

[16/Apr/2002:18:29:27] INFO (10467): CorbaClientServlet: init

[16/Apr/2002:18:29:27] SEVERE (10467): StandardWrapperValve[CorbaClientServlet]: Allocate exception for

servlet CorbaClientServlet javax.servlet.ServletException: Servlet.init() for servlet CorbaClientServlet threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrappe r.java:935) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.j ava:653)

...

----- Root Cause -----

java.lang.NoClassDefFoundError: com/iona/corba/util/SystemExceptionDisplayHelper at samples.corba.common.OrbSingleton.<init>(OrbSingleton.java:40) at samples.corba.common.OrbSingleton.getInstance(OrbSingleton.java:51)


java.lang.NullPointerException

Double check the CLASSPATH of the application server to ensure that the name of the directory under which the licenses.txt file is located is part of the CLASSPATH. Refer to the E2A Application Server Platform 5.1 Configuration document for more details.

Browser output:

exception

javax.servlet.ServletException: Servlet.init() for servlet CorbaClientServlet threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrappe r.java:935) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.j ava:653)

...

root cause

java.lang.NullPointerException at samples.corba.servletsample.CorbaClientServlet.init(CorbaClientServ let.java:66) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrappe r.java:916)

Server log:

[16/Apr/2002:18:42:00] INFO (10486): CorbaClientServlet: init

[16/Apr/2002:18:42:00] SEVERE (10486): StandardWrapperValve[CorbaClientServlet]: Allocate exception for servlet

CorbaClientServlet javax.servlet.ServletException: Servlet.init() for servlet CorbaClientServlet threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrappe r.java:935) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.j ava:653)

...

----- Root Cause -----

java.lang.NullPointerException at samples.corba.servletsample.CorbaClientServlet.init(CorbaClientServ let.java:66) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrappe r.java:916)


CORBA.TRANSIENT Exception

Ensure that the demos.simple.Server application has been started. Refer to the E2A Application Server Platform 5.1 Configuration document for more details. Upon restarting the CORBA server application and executing the servlet again, the servlet should work properly.

Browser output:

Invoking method on first object.

Caught org.omg.CORBA.TRANSIENT exception.org.omg.CORBA.TRANSIENT: cannot establish binding vmcid:

0x49540000 minor code: 770 completed: No

Invoking method on second object.

Caught org.omg.CORBA.TRANSIENT exception.

Done

Server log:

[16/Apr/2002:18:21:43] INFO (10356): CorbaClientServlet: Invoking method on first object.

[16/Apr/2002:18:22:00] INFO (10356): Caught org.omg.CORBA.TRANSIENT exception.org.omg.CORBA.TRANSIENT:

cannot establish binding vmcid:

0x49540000 minor code: 783 completed: No

[16/Apr/2002:18:22:00] INFO (10356): CorbaClientServlet: Trying to reinitialize object refs.

[16/Apr/2002:18:22:00] INFO (10356): CorbaClientServlet: Invoking import_object() for first object

[16/Apr/2002:18:22:00] INFO (10356): CorbaClientServlet: Reading object reference from /space/sanju/install/orbix_2000/orbix_art/1.2/demos/simple1.ior

[16/Apr/2002:18:22:00] INFO (10356): Invoking import_object() for second object

[16/Apr/2002:18:22:00] INFO (10356): CorbaClientServlet: Reading object reference from /space/sanju/install/orbix_2000/orbix_art/1.2/demos/simple2.ior

[16/Apr/2002:18:22:00] INFO (10356): CorbaClientServlet: Invoking narrow on first object.

[16/Apr/2002:18:22:00] INFO (10356): CorbaClientServlet: Invoking narrow on second object.


Class Cast Exception

Ensure that the demos.simple.Server application has been started. Refer to the E2A Application Server Platform 5.1 Configuration document for more details. Upon restarting the CORBA server application and executing the servlet again, the servlet should work properly. The cause of this problem is likely the same as the cause of the CORBA.TRANSIENT Exception, but the circumstances of the timing are different.

Browser output:

Invoking method on first object.

Caught unexpected exception.java.lang.ClassCastException: com.sun.corba.ee.internal.corba.AnyImpl

Server log:

[16/Apr/2002:18:12:30] INFO (10356): CorbaClientServlet: Invoking method on first object.

[16/Apr/2002:18:12:30] INFO (10356): Caught unexpected exception.java.lang.ClassCastException: com.sun.corba.ee.internal.corba.AnyImpl


Further Exploration

Using a Singleton for ORB Initialization describes how to implement the singleton to manage ORB initialization.

EJB Accessing Backend CORBA Objects via IONA Orbix is a simple sample of an EJB accessing the same backend CORBA object as demonstrated in the servlet example.


Previous      Contents      Next     
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated August 09, 2002