...
Anchor | ||||
---|---|---|---|---|
|
A typical J2EE application may contain Enterprise JavaBeans or EJBs. These beans contain the application's business logic and live business data. Although it is possible to use standard Java objects to contain your business logic and business data, using EJBs addresses many of the issues of using simple Java objects, such as scalability, lifecycle management and state management.
...
- Session Beans implementation analysis
- Sample application
- The JBoss environment
- The Geronimo environment
- Step-by-step migration
- Summary
...
EJB implementation analysis
Anchor | ||||
---|---|---|---|---|
|
EJB implementation may vary from one vendor to another. The purpose of this section is to provide a session bean specific feature-to-feature comparison between JBoss and Apache Geronimo so you can clearly identify the differences and plan accordingly before migration.
...
Feature | JBoss v4 | Apache Geronimo (OpenEJB) |
---|---|---|
Stateful and stateless Session Beans | supported | supported |
BMP (Bean Managed Persistence) Entity Beans | supported | supported |
CMP (Container Managed Persistence) Entity Beans | supported | supported |
Message driven beans (MDBs) | supported | supported |
Interoperability using RMI-IIOP or JAXRPC | supported | supported |
Ability to expose stateless session beans and MDBs as Web Services | supported | supported |
Support for sending and receiving messages via Web Services | supported | supported |
Easy provisioning and hot deployment of EJB and JMX-based Web Services | supported | supported |
Access to EJBs from external CORBA objects | supported | supported |
Sample application
Anchor | ||||
---|---|---|---|---|
|
This Session Bean Sample Application shows how session beans are used and deployed in a container. There are two
...
This sample application shows how session beans are used and deployed in a container. There are two clients, one for stateless session beans and another for stateful session beans. Both client applications use the same database which contains a table that stores loan application details. An entity bean is used to connect to and operate on the loan details table. A session bean is then used by the client application to get specific details from the database using the entity bean. The first client creates a stateless session bean and displays a list of denied loan applications via a method defined in that EJB. The second client creates a stateful session bean and adds loan applications to the database.
The following figure illustrates the application flow:
Application Beans
...
Download the Session Bean sample application from the following URL:link:
Session Bean Samplehttp://opensource2.atlassian.com/confluence/oss/download/attachments/1155/session.zip
After extracting the zip file, a session directory will be created. From now on, this directory will be referred as <session_home>.
...
This will compile the source files and package the EJB jar file. You can see the results in the <session_home>/target directory. The following list shows the dependency jars needed in building and running the Session Bean sample application.
- geronimo-spec-ejb-_2.1_spec-rc41.0.jar - the EJB spec; needed for compiling source.
- openejb-core-2.0-G1M5.jar - needed by Geronimo during runtime.
- geronimo-spec-j2ee-_1.4_spec-rc41.0.jar - needed by Geronimo during runtime.
- geronimo-security-1.0-M5.jar - needed by Geronimo during runtime.
...
The following figures illustrate the home page for the Web Application as well as the testing for the stateless and stateful beans depending on your selection on the Web Application home page.
The Geronimo environment
Anchor | ||||
---|---|---|---|---|
|
...
CREATE TABLE CUSTOMER(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(45),BIRTHDATE DATE,SSS_NO VARCHAR(25),ADDRESS VARCHAR(60),ANNUAL_SALARY DOUBLE,LOAN_AMOUNT DOUBLE)
Step-by-step migration
Anchor | ||||
---|---|---|---|---|
|
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar" xmlns:naming="http://geronimo.apache.org/xml/ns/naming" xmlns:security="http://geronimo.apache.org/xml/ns/security" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment" configId="geronimo/SessionBeanDemo/1.0/car" parentId="orggeronimo/apache/geronimo/Serverj2ee-server/1.0/car"> <enterprise-beans> <entity> <ejb-name>CustomerEJB</ejb-name> <jndi-name>CustomerHomeRemote</jndi-name> <local-jndi-name></local-jndi-name> <resource-ref> <ref-name>jdbc/ibm-demo</ref-name> <resource-link>SystemDatasource</resource-link> </resource-ref> </entity> <session> <ejb-name>LoanManagerEJB</ejb-name> <jndi-name>LoanManagerHomeRemote</jndi-name> <ejb-ref> <ref-name>ejb/CustomerHomeRemote</ref-name> <ejb-link>CustomerEJB</ejb-link> </ejb-ref> </session> <session> <ejb-name>StatefulLoanManagerEJB</ejb-name> <jndi-name>StatefulLoanManagerHomeRemote</jndi-name> <ejb-ref> <ref-name>ejb/CustomerHomeRemote</ref-name> <ejb-link>CustomerEJB</ejb-link> </ejb-ref> </session> </enterprise-beans> </openejb-jar> |
As with all Geronimo deployment plans, this configuration requires a parent configuration. In this case, it is orggeronimo/apache/geronimo/Serverj2ee-server/1.0/car, then follows the definition of the EJBs.
...
- ejb-name - identifies the EJB that these settings apply to; this should match the ejb-name for the EJB in ejb-jar.xml
- jndi-name - the Home interface for the EJB is registered in JNDI at the address specified here; this global JNDI name is used by application clients to connect to this EJB (while it can be used by other server-side components, EJB references are the recommended approach); it is only meaningful if the EJB has a (remote) Home interface.
- local-jndi-name - the LocalHome interface for the EJB is registered in JNDI at the address specified here; this global JNDI name can be used by other server-side components that want to use this EJB, though the recommended approach is to define and use a local EJB reference instead; it is only meaningful if the EJB has a LocalHome interface.
- tssGroup - this is a set of elements that contains CORBA security settings, for EJBs exposed as CORBA objects; it is not necessary if the EJB will not be accessed via CORBA.
- openejb-jndiEnvironmentRefsGroup - a set of elements that handle resolving references declared by the current Session bean (including EJB references, Resource references, and Web Service references).
Set the JNDI properties
Edit the jndi.properties file located in in the <session_home>/jndi directory as shown in the following example:
No Format | ||||
---|---|---|---|---|
| ||||
####################################################################
### JBoss Settings
####################################################################
#java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
#java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
#java.naming.provider.url=localhost
####################################################################
### Geronimo Settings
####################################################################
java.naming.factory.initial=org.openejb.client.RemoteInitialContextFactory
java.naming.provider.url=localhost:4201
java.naming.security.principal=username
java.naming.security.credentials=passwd |
...
java.naming.security.credentials=passwd |
Modify the WAR files
Open the web.xml file located in the <session_home>/src/webapp/WEB-INF directory and comment out the following taglib element:
...
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
- this is used for Apache Geronimo.
Build the sample application
Build the migrated Session Bean sample application by running the following command from the <session_home> directory:
maven ejb war
This command will create the session-ejb-SNAPSHOT.jar and session-ejb.war files in the <session_home>/target directory.
Deploy the migrated application
In order to deploy the application make sure the Geronimo server is up and running. From a command line change directory to <session_home> and type the following command:
maven geronimo:deploy
Once the application is deployed and started you can verify its status by typing the following command from the <geronimo_home>/bin directory:
...
Look for the SessionBeanDemo entry and SessionWebApp entries.
To test the migrated Session Bean application run the following commands from the <session_home> directory:
...
No Format bgColor #000000 borderStyle solid
E:\session>maven run-g:stateless
__ __
| \/ |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \ ~ intelligent projects ~
|_| |_\__,_|\_/\___|_||_| v. 1.0.2
build:start:
run-g:stateless:
[java] Customers with denied loan applications:
[java] - Customer1
[java] - Customer6
BUILD SUCCESSFUL
Total time: 3 seconds
Finished at: Wed Nov 02 13:11:39 EST 2005
As with JBoss, you can also run the Web Application client by pointing a Web browser to the following URL:
As with JBoss, the following figures illustrate the home page for the Web Application as well as the testing for the stateless and stateful beans depending on your selection on the Web Application home page.
Summary
Anchor | ||||
---|---|---|---|---|
|
This article has shown how to migrate a sample application that uses Session Beans, from JBoss v4.0.2 to Apache Geronimo M5. This article provided step-by-step instructions to build the application, deploy and run it, and then migrate it to the Geronimo environment.
...