Inside Scoop on J2EE : Tips and tricks on J2EE and Oracle Application Server by Debu Panda
Updated: 11/14/2005; 11:24:45 AM.

 

Subscribe to "Inside Scoop on J2EE" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Wednesday, October 12, 2005

Interoperability is reality of most of our lives. Although I'm NOT a big advocate for this kind of architecture, many projects require separation of the presentation layer from business logic layer in containers from different vendors. For example, some projects require deployment of presentation-tier (web module) in Apache Tomcat and business logic tier (EJB module) in a remote J2EE container such as OC4J. In this blog, I will outline steps required to configure Apache Tomcat to remotely access EJB in a J2EE container such as OC4J 10.1.3.

 

Deploy the EAR containing the EJB Module in the J2EE container Let us take an example, a simple EJB named Hello is packaged in an EAR named hello.ear and deployed in OC4J instance with an application name hello.

 

Identify the RMI protocol and Context Factory. Most J2EE containers support their proprietary RMI protocol and RMI-IIOP. The proprietary RMI protocols are often lightweight and better in performance than RMI-IIOP. In our example, we will use ORMI (Oracle’s proprietary RMI protocol). We will use oracle.j2ee.rmi.RMIInitialContextFactory.

 

Identify the client side libraries that you require to lookup an EJB and make it available to Tomcat OC4J 10.1.3 requires oc4jclient.jar at the client-side for looking up EJB using ORMI.

 

You have to make the client side jars available in Tomcat classpath. Optionally, you can package oc4jclient.jar in the WEB-INF/lib of the web module that access the EJB. Additionally you have to make J2EE specific jars such as ejb.jar available to Tomcat.

 

Package EJB interfaces

You have to package the home and interfaces of the EJB in WEB-INF/classes or the jar containing the interfaces in WEB-INF/lib directory of the wen module being deployed in Tomcat.

 

Populating JNDI environment variable and look up EJB in your Servlet/JSP

Here is the code you have in your Servlet/JSP to populate the JNDI environment and lookup the EJB as follows:

 

      Hashtable env = new Hashtable();

      env.put(Context.INITIAL_CONTEXT_FACTORY, "oracle.j2ee.rmi.RMIInitialContextFactory");

      env.put(Context.PROVIDER_URL, "ormi://localhost:23791/hello");

      env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin");

      env.put(Context.SECURITY_CREDENTIALS, "welcome");

     

     Context ic = new InitialContext(env);

     

      HelloHome home = (HelloHome)PortableRemoteObject.narrow(ic.lookup("HelloBean"), HelloHome.class);

      Hello remote = (Hello) home.create();

 

        System.out.println(remote.sayHello("Debu"));

 

 

 

Most containers (like that of OC4J) support packaging a jndi.properties containing the JNDI environment variables and packaging that in WEB-INF/classes. However I couldn't make that to work in Tomcat 5.0.30. Some searches in google suggested that I disable global JNDI in Tomcat by starting with -nonaming and when I tried to use that flag Tomcat failed to start. I recommend that you jndi.properties if that works. If you know how to make jndi.properties to work in web module in Tomcat 5.0.x please do not forget to eligthen me.

 

You can create the WAR and deploy that to Tomcat. Now you should be able to run your web module that invokes the EJB deployed in OC4J!


5:50:08 AM    comment []

© Copyright 2005 Debu Panda.

PS: These are my own thoughts and not of my employer ..



Click here to visit the Radio UserLand website.
 


October 2005
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Sep   Nov