This topic shows you step-by-step how to deploy a CMP entity bean from IBM WebSphere 3.5 to WebLogic 5.1.0 and run a client for it.
Copy EJB-related files from WebSphere\AppServer\EJBSamples\src into a directory structure according to the package statements (e.g. TG_HOME%\samples\java\ejb\WebSphere\WebSphereSamples\Increment). Thus, the example will reside in the same place with the beans.
Increment.java
IncrementBean.java
IncrementKey.java
IncrementHome.java
VisitIncrementSite.java
Start Together and create project in %TG_HOME%\samples\java\ejb\WebSphere\WebSphereSamples\Increment.
Together automatically recognizes the structure of parent
directories, so that the upper folders correspond to the package
statements. This helps avoid errors.
Click on the Bean implementation class, go to
EntityEJB and look at the properties.
Together recognizes fully qualified names of the classes, interfaces etc.
Go to Properties | EntityEJB | Properties of the IncrementBean
and set "JNDI name to bind to" to Increment
(it was not recognized by Together since it is stored in XML file
rather than in the sources. ).
Select Fields
and Finders tab and set column property for "count"
field to "counts" . Note:
the word "count" is reserved.
Select DB binding tab and make sure that table name is set to "Increment", and pool name is set to "demoPool".
EJB is now ready. Let us create a table in the cloudscape database.
Go to Tools | Generate DDL and select: "Export from:"
-"Enterprise Java Bean".
Select "Diagram name:" -
"Increment", and press Next.
Select "Generate and Run DDL". Specify the settings listed below and press Next.
|
Field |
Value |
|
Server type |
CloudScape |
|
Set class path |
%WL_HOME%/eval/cloudscape/lib/cloudscape.jar |
|
Set Database |
%WL_HOME%/eval/cloudscape/data/demo |
Make sure that Schema name is set to APP.
Press Edit DDL button and rename "count"
field to "counts". Change primaryKey type from VARCHAR(1)
to VARCHAR(10).
Press FINISH button.
Restart Together (The evaluation version of Cloudscape that ships with WebLogic Server supports only one database connection at a time to a cloudscape.system.home directory http://www.weblogic.com/docs51/techsupport/cloudscape.html#settingup )
Ok, we're ready for take off!
Start WLS Server (either manually from Start menu, or via using of our starter plug-in). Uncomment the following lines in %WL_HOME%\weblogic.properties before you run the server:
"weblogic.httpd.register.servlets=weblogic.servlet.ServletServlet"
"weblogic.allow.reserve.weblogic.jdbc.connectionPool.demoPool=everyone"
"weblogic.jdbc.connectionPool.demoPool=\
url=jdbc:cloudscape:demo,\
driver=COM.cloudscape.core.JDBCDriver,\
initialCapacity=1,\
maxCapacity=2,\
capacityIncrement=1,\
props=user=none;password=none;server=none"
This allows to run unregistered servlets from the servlet classpath.
Start deployment to WLS5.1. All checkboxes, except Create Database Table for CM EJB, should be on.
Specify correct paths / host / password / whatever required by the Expert, and click Finish.
In the XMLEditor for ejb-jar.xml go to ejb-jar/enterprise-beans/session/Description (*)and make sure that description for the IncrementBean has been retrieved directly from the sources, without any user's efforts! Check that EJBName is short IncrementBean. Click Ok to continue.
In the XMLEditor for weblogic-ejb-jar.xml go to weblogic-ejb-jar/weblogic-enterprise-bean/ejb-name and make sure it is IncrementBean. The associated JNDI name in weblogic-ejb-jar/weblogic-enterprise-bean/jndi-name is Increment. It is taken from the properties, specified in the previous step. Click Ok to continue.
After a while Together will display a message
WLS51: Finished with 0 Errors, 0 Warnings
WLS console displays a message like:
Fri Aug 25 12:06:44 GMT+02:00 2000:
EJB home interface: 'WebSphereSamples.Increment.IncrementHome' deployed bound to the JNDI name: 'Increment'
Ok, deployment complete. Now let us make some changes to the client.
Select VisitIncrementSite.
Find the string
incrementHome = (IncrementHome)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object) homeObject, IncrementHome.class);"
and remove org.omg.CORBA.Object)
Select init() method and make the following changes:
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL,
provider);
env.put(Context.INITIAL_CONTEXT_FACTORY,
factory);
Find InitialContext ctx = new InitialContext(env); and replace with InitialContext ctx = new InitialContext();
Select doGet method.
out.println(<form method="get" action="/servlet/WebSphereSamples.Increment.VisitIncrementSite\"");
and replace it with
out.println(<form method="get" action="/servlets/WebSphereSamples/Increment/VisitIncrementSite\"");
Compile VisitIncrementSite and copy VisitIncrementSite.class into a directory structure according to the package statements (e.g. %WL_HOME%\myserver\servletclasses\WebSphereSamples\Increment).
Run the client.
Start your browser and open http://localhost:7001/servlets/WebSphereSamples/Increment/VisitIncrementSite.
Observe "Increment a Counter....."