This sample is based on the Product EJB sample included in Sun's J2EE Developer's Guide, version 1.2.1 . The following instructions describe how to assemble and deploy the same EJB to iPlanet Application Server and how to access the EJB from both a simple Java client application using RMI/IIOP as well as from a Servlet client using HTTP. Although the client application and EJB offer minimal functionality, this sample should provide you with a basic understanding of RMI/IIOP and CMP support in iPlanet Application Server.
Setting Up the Environment
Getting Started includes a checklist of prerequisites for deploying sample applications to iPlanet.
J2EE Developer's Guide Samples Notes describes special considerations when deploying these sample.
Enable RMI/IIOP Support in the application server. (Performed automatically in a Test Drive installation).
Configuring the Database describes how to setup the database schema, load the content and register the JDBC data sources for the application.
Deploying and Running the Application
Select one of two approaches to deploying the application:
Command Line-based Deployment describes how to manually register the application in iPlanet using a Command Line Interface (CLI). This is the fastest means of deploying the application.
GUI-based Deployment describes how to use the iPlanet Deployment Tool to import and deploy the application. It also addresses assembling the application from scratch using the Deployment Tool.
Deploying the Client Application describes how to deploy the Java client application.
Running the Application describes how to start the application, navigate through it and how to troubleshoot in the event of problems.
Compiling and Assembling the Application describes how to use command line tools to recompile the sources and rebuild the WAR and EJB modules and the overall EAR file.
Ensure Database Requirements are MetEnsure Database Driver is Registered
Identify or Create a Database User
Create and Populate Sample Database Tables
This section describes how to register an underlying database driver with the application server in the event that a driver was not registered during installation of the application server. The following instructions address only the registration of the database client driver. The subsequent section of this document will describe how to populate the database tables and register JDBC data sources.
If PointBase is to be used as the database, then the driver has already been registered and the data has been loaded during installation. However, the datasource needs to be registered with the application server. Got to the directory:
install_dir/ias/ias-samples/j2eeguide/product/src/schema/
And execute the command:
iasdeploy regdatasource ProductDB-pointbase-type4.xml
Use of the iasdeploy command requires that you first register the application server instance in the application server's administration tool. Refer to the Getting Started section for more information on using the iasdeploy command.
If you are using PointBase, proceed to the next section Command Line-based deployment. If you are using Oracle, then continue with the following instructions.
The following instructions address only the registration of the database client driver. Subsequent sections of this document will describe how to populate the database tables and register JDBC data sources.
install_dir/ias/bin/ksvradmin
UNIX: Database Driver Registration
install_dir/ias/bin/db_setup.sh
To define a new Oracle user:
SQL > create user j2eeguide identified by j2eeguide;
Where the first j2eeguide is the user name and the second j2eeguide is the password.
SQL> grant connect, resource, dba to j2eeguide identified by j2eeguide;
A shell script named setup_<rdbms type>.sh/.bat configures the database tables, populates the tables with sample data and updates the application server's registry with database information to support the sample application. The setup_<rdbms type>.sh/.bat script performs the following steps:
UNIX: Create and Populate RDBMS
For example,3. Run setup_<dbname>.sh with the following arguments:GX_ROOTDIR=/usr/iplanet/ias6/ias
setup_ora.sh <TNS name> <dbusername> <dbpassword>For example using Oracle:setup_ora.sh iassample j2eeguide j2eeguideWhere:
<TNS Name> is the Oracle service or TNS name which maps to the appropriate Oracle database instance. In the example above, "iassample" is the Oracle service or TNS name. (This assumes that the Oracle client has been configured to recognize "iassample" as a valid Oracles service/TNS name.)
<dbusername> and <dbpassword> are the Oracle user name and password under which the tables will be created and populated. These are also the values that will be used by the sample application to access the Oracle database.
Since the setup_ora.sh script uses sqlplus, ensure that LD_LIBRARY_PATH includes $ORACLE_HOME/lib.
2. Run setup_<rdbms type>.bat with the following arguments:
setup_ora <TNS name> <dbusername> <dbpassword>
For example using Oracle:
setup_ora iassample j2eeguide j2eeguideWhere:<TNS Name> is the Oracle service or TNS name which maps to the appropriate Oracle database instance. In the example above, "iassample" is the Oracle service or TNS name. (This assumes that the Oracle client has been configured to recognize "iassample" as a valid Oracles service/TNS name.)
<dbusername> and <dbpassword> are the Oracle user name and password under which the tables will be created and populated. These are also the values that will be used by the sample application to access the Oracle database.
The pre-built j2eeguide-product.ear file is a Enterprise ARchive file that contains the Web Archive (WAR) and EJB JAR files for the Product application. Within each of these JAR files reside the XML deployment descriptor files, application class files, JSPs and other content required by the application.
Deploying the pre-built j2eeguide-product.ear file is simple.
1. Go to the root of the Product sample directory:
install_dir/ias/ias-samples/j2eeguide/product/
2. Execute iasdeploy to deploy application to the local application server instance:
iasdeploy deployapp j2eeguide-product.ear
Refer to the Getting Started section for more information on using the iasdeploy command.
The deployment process involves the following operations:
Now you're ready to exercise the application by Deploying the Client Application.
Two approaches to using the Deployment Tool are described:
Import Pre-existing EAR File to quickly deploy the application to iPlanet using the Deployment Tool. None of the application assembly steps are covered by this section. On average, this approach will take 10 minutes.or
Assemble the Application to learn how to use Deployment Tool to assemble the application from scratch and to deploy it to the application server. On average, this approach will take from 15-25 minutes.
1. Launch the Deployment Tool.
UNIX:Execute install_dir/ias/bin/deploytoolWindows:Start->Programs->iPlanet Application Server 6.0->iAS Deployment Tool
2. Open the EAR file
Proceed to Deploying the Application
To compile the application sources, simply execute "build compile" under the application's src/ directory. See the section Compiling and Assembling the Application for more information on recompiling the application using the supplied build facility.
Create the new directory install_dir\ias\ias-samples\j2eeguide\product\assemble\ outside the Deployment Tool. You will assemble the application into JAR files and save them to this directory.2. Launch the Deployment Tool:
UNIX: Execute install_dir/ias/bin/deploytool&3. Create j2eeguide-productEjb.jar:Windows: Programs->iPlanet Application Server 6.0->iAS Deployment Tool
4. Now insert all class files needed in the j2eeguide-productEjb.jar file:
1. Modify Descriptor for Product EJB
2. Begin Modifying the Product EJB Descriptor
|
|
|
|
description | java.lang.String | false | DESCRIPTION |
price | double | false | PRICE |
productId | java.lang.String | true | PRODUCTID |
|
|
|
findByDescriptionParms | java.util.Vector | description |
findByDescriptionSQL | java.lang.String | select PRODUCTID from PRODUCT where DESCRIPTION = ? |
findInRangeParms | java.util.Vector | low,high |
findInRangeSQL | java.lang.String | select PRODUCTID from PRODUCT where PRICE between ? and ? |
3. Close the Descriptor for the EJB
Now we can close the EJB descriptor by clicking on the X in the upper right hand corner of the descriptor window. Click on Yes when asked to save the changes.
Now that we've assembled the EJB JAR module, we're ready to move on to assembling the Web Application aRchive (WAR) file.
1. Create j2eeguide-product.war:
2. Now insert all class files needed in the j2eeguide-product.war file:
Now we need to make several changes to settings at the WAR module level. To do so, select either the WAR file path if in File View or the WAR module name if in Component View. Right click and select Edit Descriptor.
As described for the j2eeguide-productEjb.jar, in the following paragraphs, the title gives the tab name, where you have to enter the data given below.
1. General Tab
Name: j2eeguide-product Distributable checked Session Timeout (seconds): 500 (take server default)
2. iAS Tab
Distributed Session checked Timeout (minutes): 15 Timeout Type Since last access Data Synchronization Distributed
Now that we've assembled both J2EE modules (EJB JAR and WAR), we're ready to move on to assembling the modules into an EAR file.
1. Create j2eeguide-product.ear:
2. Add j2eeguide-productEjb.jar and j2eeguide-product.war Files:
3. Set the EJB references
Next, we need to set the EJB references from the WAR module
EJB References:
Reference | Bean Type | Bean Home Interface | Bean Remote Interface | Linked to Bean |
MyProduct | Entity | j2eeguide.product.ProductHome | j2eeguide.product.Product | MyProduct |
4. Set Context Root for Web Application
Next, we need to set the context root of the web application. This value will appear in URLs that access web application components. For example, in the URL http://localhost/NASApp/j2eeguide-product/ProductServlet the "j2eeguide-product" value is the context root of the web application.
4. Save j2eeguide-product.ear:
Now that the EAR file has been assembled, the next step is to deploy the application to an application server instance.
Now you're about to deploy the application by transferring the EAR file to a target iPlanet Application Server. First, you will identify the target server. After the EAR file is deployed to the server, post processing is performed. The post processing step involves running iasdeploy against the transferred j2eeguide-product.ear file. You will see the output from iasdeploy fed back to the deployment window. After this step, you will be able to run the application. No server restart is required.
Although you could perform the deployment steps manually by transferring the EAR file to the remote application server and executing j2eeappreg to register the EAR file, Deployment Tool provides a point and click means of deploying applications to remote iPlanet Application Servers.
If you followed the assembly instructions, then j2eeguide-product.ear is opened in Deployment Tool. If you opened the pre-existing EAR file, you are working with install_dir\ias\ias-samples\j2eeguide\product\j2eeguide-product.ear. If you are following the "Create EAR File from Scratch" instructions, you are modifying install_dir\ias\ias-sample\j2eeguide\product\assemble\j2eeguide-product.ear.
If you entered all deployment information manually, you can skip the following steps 1 to 3, because you have entered this information already.
1. Select the j2eeguide-product.ear file under the J2EE Application window.
2. Select File -> Deploy
3. If you have not already registered a target application server, do so now by clicking on the Register button. Enter the host name, administrative port number and username/password for the target application server. Otherwise, select a pre-registered target server.
Note: You may authorize additional users to deploy applications to an iAS server by using the iAS Administrative Console. See the Security settings tab in the iAS Administrative Console.
4. Click on Overwrite modules in case you are repeating the deployment step.
5. Click on Deploy to start the deployment process.
6. Now the file transfer and application registration begins. See the Deploy tab for the status of the deployment. Once the status of the deployment changes to Success, proceed to the next section.
UNIX:install_dir/ias/bin/ksvradminWindows:Start->Programs->iPlanet Application Server->iAS Administration Tool
Although in practice, you will most likely script the following client application deployment steps, the manual steps are described below in order to provide you with a sense of deploying an RMI/IIOP client. Since manual steps such as setting CLASSPATH variables and such are prone to error, please review each step carefully.
As you review the sample build facility described in Compiling and Assembling the Application, you'll note the install_client target that automates steps 1, 5 and 6. Since the other steps are one time configuration changes, using the "build install_client" command will prove to be a great time saver for local client redeployments.
For example, on UNIX:
For example, on Windows:/opt/rmi-client/
d:\rmi-client\
If you are planning to run the Java application client on a machine other than the one on which the application server resides, refer to the RMI/IIOP chapter of the Developer's Guide for details on the configuration of the remote client environment.
Ensure that the PATH and CLASSPATH variables reference the appropriate JDK, javax.jar and iasclient.jar files.
Testing RMI/IIOP Client Access to EJBs on Same System
If you are experimenting with RMI/IIOP client access using a client that
is on the same machine as the application server, you can take a shortcut to
setting up the PATH and CLASSPATH variables. Simply reference the existing,
pre-installed copies of the javax.jar,
iasclient.jar
and usr/java/bin/. For
example, to test RMI/IIOP access locally, set the CLASSPATH variable as follows
(since the Windows System PATH environment variable already contains usr/java/bin/
of the bundled JDK, there is no need to set this again on Windows):
Windows:
set CLASSPATH=d:\iplanet\ias6\ias\lib\java\javax.jar;d:\iplanet\ias6\ias\classes\java\iasclient.jar;%CLASSPATH%
You could set the Windows System CLASSPATH to avoid having to manually set the variable.
UNIX:
export CLASSPATH=/usr/iplanet/ias6/ias/classes/java/javax.jar:/usr/iplanet/ias6/ias/classes/java/iasclient.jar:$CLASSPATH
On UNIX, you will also need to modify the PATH to include the bundled JDK directory:
export PATH=/usr/iplanet/ias6/ias/usr/java/bin:$PATH
Testing RMI/IIOP Client Access to EJBs from a Remote System
If you are
using a remote client system, then follow these steps to establish the appropriate
PATH and CLASSPATH settings.
UNIX
Set your PATH environment variable to include the appropriate Java 2 bin/ directory:
export PATH=<Java 2 install>/usr/java/bin:$PATH
Set your CLASSPATH to include the standard Java Extension classes and the iPlanet RMI/IIOP client support JAR:
export CLASSPATH=/opt/rmi-client/iasclient.jar:/opt/rmi-client/javax.jar:$CLASSPATH
Doublecheck the CLASSPATH to ensure that it is set correctly (your CLASSPATH may vary from the one shown below).
echo $CLASSPATH
/opt/rmi-client/iasclient.jar:/opt/rmi-client/javax.jar:
Windows
Set your PATH environment variable to include the appropriate Java 2 bin/ directory:
set PATH=<Java 2 install>\usr\java\bin;%PATH%
Set your CLASSPATH to include the standard Java Extension classes (javax.jar) and the iPlanet client support JAR (iasclient.jar).
set CLASSPATH=d:\rmi-client\javax.jar;d:\rmi-client\iasclient.jar;%CLASSPATH%
Copy ProductClient.class to...
UNIX: /opt/rmi-client/j2eeguide/product/Set your client's CLASSPATH to include the Product client directory path:Windows: d:\rmi-client\j2eeguide\product\
UNIX:
This setting will enable both the application main class as well as the Product-specific EJB interfaces and stubs to be accessed at run time.Windows:export CLASSPATH=/opt/rmi-client:$CLASSPATH
set CLASSPATH=d:\rmi-client;%CLASSPATH%
Product EJB Interface Classes:
EJB-Specific iPlanet Client Stubs:
Before running the sample, first double check your work thus far by ensuring that:
From the rmi-client/ directory, execute the following command:
java j2eeguide.product.ProductClient <hostname> <port>
For example,
java j2eeguide.product.ProductClient hamlet 9010
Where:
The application should emit the following messages:<hostname> is the host name of the application server.
<port> is the IIOP port number of the RMI-IIOP bridge or cxs process on the application server.
Ceramic Dog: 10.0
Ceramic Dog: 14.0
Chrome Fish: 22.0
999: Ivory Cat 19.0
789: Ivory Cat 33.0
123: 14.0
456: 13.0
999: 19.0
Compare this output with the ProductClient.java source code.
After client application completes, the PRODUCT table should contain the following rows:
SQL> select * from product;
DESCRIPTION PRICE PRODUCTID
----------- ----- ------------------------------
Ceramic Dog 14 123Wooden Duck 13 456
Ivory Cat 19 999
Ivory Cat 33 789
Chrome Fish 22 876
Before rerunning the application client again, ensure that you reset the database table by either rerunning the product/src/schema/setup_ora script or by removing all rows from the table. The application will not work correctly unless you clean up the database table.
If you are using PointBase, you can remove and recreate the sample table by using the supplied src/schema/product_pb.sql script and the PointBase tools described in Using PointBase with iPlanet guide.
Go to the following URL to exercise the servlet front end:
http://<hostname>/NASApp/j2eeguide-product/ProductServlet
If your deployment process was successful, the servlet sends the following information to your browser:
Ceramic Dog: 10.0
Ceramic Dog: 14.0
Chrome Fish: 22.0
999: Ivory Cat 19.0
789: Ivory Cat 33.0
123: 14.0
456: 13.0
999: 19.0
Compare the resulting web page with the ProductServlet.java source code.
After servlet application completes, the PRODUCT table should contain the following rows:
SQL> select * from product;DESCRIPTION PRICE PRODUCTID
----------- ----- ------------------------------
Ceramic Dog 14 123Wooden Duck 13 456
Ivory Cat 19 999
Ivory Cat 33 789
Chrome Fish 22 876
Before rerunning the application client again, ensure that you reset the database table by either rerunning the product/src/schema/setup_ora script or by removing all rows from the table. The application will not work correctly unless you clean up the database table.
If you are using PointBase, you can remove and recreate the sample table by using the supplied src/schema/product_pb.sql script and the PointBase tools described in Using PointBase with iPlanet guide.
If you encounter problems when running the application, review the General Troubleshooting section to learn how to view logs files. Also review the Troubleshooting section of the RMI/IIOP chapter of the Developer's Guide.
If you don't receive data in the browser and the kjs log shows a "ORA-00001: unique constraint ..." message in the log or a "javax.ejb.DuplicateKeyException" in the rich client, the condition is most likely one in which the sample was run at least partially before. Consequently, there are rows in the Product table. Since this simple sample is not designed to handle this condition, you must manually remove all rows from the table prior to executing the application. Open a sqlplus session and enter TRUNCATE TABLE PRODUCT; to remove all entries from this table. Alternatively, rerun the product/src/setup_ora.sh/.bat script to drop and recreate the Product table.
To easily recompile, assemble and deploy the application, see the Sample Application Build Facility document for details on using a build facility to quickly perform these tasks.
For example, to rebuild the entire application from scratch, follow these steps:
1. Compile and Assemble EJB JAR Components and Web Application
Execute "build" under j2eeguide/product/src/
The default target core will be executed to rebuild the EJB JAR and WAR files as well as the web application's EAR file.
2. Redeploy Application
Execute "build deploy" under j2eeguide/product/src/
3. Install the Java Client Application
Execute "build install_client" under j2eeguide/product/src/
Executing this target will install the class files required to run the client application under:
<iPlanet install path>/ias/rmi-client/
4. Restart Application Server
An application server restart will be necessary if you've modified either deployment descriptors or EJBs. For servlet and/or JSP modification, no restart is is necessary.
To clean the application build and assembly areas, execute "build clean".