|
Page Edited :
OPENEJB :
Tomcat ObjectFactory
Tomcat ObjectFactory has been edited by David Blevins (Nov 07, 2005). Content:Leveraging J2EE JNDI principles AbstractJava 2 Enterprise Edition (J2EE) provides several technologies that lets build J2EE-compliant applications that can be run in any J2EE-compliant application server. One of the several technologies is Java Naming and Directory Interface (JNDI). JNDI is a technology that provides a unified access to different naming and directory services. Regardless of the underlaying service, if it supports JNDI a client doesn't have to know what exactly application it's to talk to other than it adheres to JNDI concepts and interfaces. OpenEJB and Tomcat can complement each other in fullfiling J2EE principles. OpenEJB is an EJB container whereas Tomcat is a servlet container. Although they serve different clients, both products use JNDI extensively. Obviously, either container provides different JNDI "views" of its managed components. The question pertaining to the integration is how to tie the different naming systems so that when a client requests an object from Tomcat naming space, Tomcat will know that it needs to pass the request along to OpenEJB naming space. That's what the object factory is to solve out. While reading JNDI specification you can come across the interface: javax.naming.spi.ObjectFactory The JNDI framework allows for object implementations to be loaded in dynamically via object factories. For example, when looking up a printer bound in the name space, if the print service binds printer names to References, the printer Reference could be used to create a printer object, so that the caller of lookup can directly operate on the printer object after the lookup. Before we startBefore we start, ensure that OpenEJB and Tomcat are in appropriate releases.
Referencing EJBs in web applicationJ2EE 1.3 specification says (page 57): The Application Component Provider must declare all the EJB references using the ejb-ref elements of the deployment descriptor. This allows the consumer of the application component's jar file (the Application Assembler or Deployer) to discover all the EJB references used by the application component. It means that each time a web application needs to reference a bean, the bean has to be declared in the web application's deployment descriptor ( /WEB-INF/web.xml file). The element which does so is ejb-ref . Although most containers don't enforce that approach, it's always better to describe dependencies in a standard, J2EE-compliant way, in the deployment descriptor of the corresponding components.
Our example's web application declares the referenced bean in the deployment descriptor ( /WEB-INF/web.xml ) as follows: <ejb-ref>
<description>
EJB Reference to the bean deployed to OpenEJB
</description>
<ejb-ref-name>ejb/hello</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>org.acme.HelloHome</home>
<remote>org.acme.Hello</remote>
</ejb-ref>
The following parameters are only required when openejb.naming.factory.initial is set to org.openejb.client.RemoteInitialContextFactory .* openejb.naming.security.principal - the name of the user who is allowed to access the JNDI context
The factory parameter indicates the class which passes a request for a bean to OpenEJB instance. In order for the class to be instantiated by Tomcat, OpenEJB Loader has to be installed. The Loader takes care of loading necessary classes from OpenEJB directory. It finds the directory relying upon OPENEJB_HOME environament variable. Create a file named setenv.sh (or setenv.bat on MS Windows) in $CATALINA_HOME/bin directory with the following content: $CATALINA_HOME/bin/setenv.sh export CATALINA_OPTS="-Dopenejb.home=$OPENEJB_HOME"
Finally, add the OpenEJB Loader to Tomcat. $ cp $OPENEJB_HOME/dist/openejb_loader-0.9.0.war webapps/ That's it. Tomcat is now fully configured to work with OpenEJB. Don't forget to start up OpenEJB instance if the factory's been configured with RemoteInitialContextFactory. Example applicationYou can use the OpenEJB Hello World as an example EJB to test things out. You won't need to do anything differently. Deploy the myHelloEjb.jar just as described in http://www.openejb.org/hello-world.html Register the factory in Tomcat by editing server.xml, i.e. add the above Ejb element declaration between Context's tags of Tomcat's default example web application. Place the JSP - openejb.jsp - in $CATALINA_HOME/webapps/examples directory. Start up Tomcat and enter http://localhost:8080/examples/openejb.jsp Tomcat should print out the following on its console (note OpenEJB messages about its startup): Using CATALINA_BASE: C:\_Jacek\apps\jakarta-tomcat-4.1.18 Using CATALINA_HOME: C:\_Jacek\apps\jakarta-tomcat-4.1.18 Using CATALINA_TMPDIR: C:\_Jacek\apps\jakarta-tomcat-4.1.18\temp Using JAVA_HOME: C:\_JACEK\APPS\JDK1.3.1 [INFO] Registry - -Loading registry information [INFO] Registry - -Creating new Registry instance [INFO] Registry - -Creating MBeanServer [INFO] Http11Protocol - -Initializing Coyote HTTP/1.1 on port 8080 Starting service Tomcat-Standalone Apache Tomcat/4.1.18 OpenEJB 0.9.0 build: 20030118-2205 http://openejb.sf.net [INFO] Http11Protocol - -Starting Coyote HTTP/1.1 on port 8080 [INFO] ChannelSocket - -JK2: ajp13 listening on 0.0.0.0/0.0.0.0:8009 [INFO] JkMain - -Jk running ID=0 time=30/241 config=C:\_Jacek\apps\jakarta-tomcat-4.1.18\conf\jk2.properties |
Unsubscribe or edit your notifications preferences
