Using Java Pet Store with Oracle
This scenario assumes that
you are already familiar with the basics of application assembly and deployment.
Before you begin
The Pet Store application and supporting files are located in the installableApps/petstore
directory:
- ps_oracle.sql - SQL command file for creating the database
tables and populating the database.
- petstore.ear - The Pet Store V1.1.2 EAR with modifications
for running on WebSphere Application Server V4.0 and DB2.
Several incompatibilities exist between WebSphere Application Server V4.0 and
V1.1.2 of the petstore.ear file, available from Sun Microsystems.
The petstore.ear file provided with WebSphere Application Server
V4.0 is already modified for you. The following list summarizes the changes made:
- Updated several deployment descriptors due to an incorrect character set
coding (ISO8859_1 instead of ISO-8859-1).
- Added OrderDAODB2.class and OrderDAOIDB.class to provide additional
database support.
- Bound the JNDI names and references.
- Updated each EJB JAR classpath to include all other EJB JARs that comprise
Pet Store.
- Updated Environmental Entries to reflect that Pet Store is running on WebSphere
Application Server, and enabled internal database support.
Configure the petstore.ear file
for use with Oracle and enable mail confirmation:
- Make a backup copy of the petstore.ear file
- Start the Application Assembly Tool (AAT):
- On Windows: assembly
- On UNIX: ./assembly.sh from /opt/WebSphere/AppServer/bin
directory
- Load the the new copy of the petstore.ear file
- Expand petstore > EJB Modules > Customer Component > Entity
Beans > TheOrder and click Environment Entries
- Change the value of the ejb/order/OrderDAOClass parameter to: com.sun.j2ee.blueprints.customer.order.dao.OrderDAOOracle
- Click Apply
- Expand petstore > EJB Modules > Petstore EJB Component >
Session Beans > TheShoppingClientController and click
Environment Entries
- Change the value of the sendMailConfirmation parameter from false
to true
- Click Apply
- Save the new configuration by clicking File > Save
- Exit AAT by clicking File > Exit
Deploying the Application
This section describes the steps to implement the Pet Store application.
Creating and Populating the Database
Locate the ps_oracle.sql file in the installableApps\petstore directory.
This .sql file creates and populates the required tables with data.
- Log on to the Oracle Database Server as an Oracle user
- Copy the ps_oracle.sql file to the Oracle Database Server
- Set the ORACLE_SID environment variable:
- On Windows:
set ORACLE_SID=oracle_sid
where: oracle_sid is the database system identifier, usually
the instance name, such as ORCL
- On UNIX:
- set ORACLE_SID=oracle_sid
where: oracle_sid is the database system identifier, usually
the instance name, such as ORCL
- export ORACLE_SID
- Change to the directory containing the ps_oracle.sql file
- From the command line, sign on to Oracle SQLPlus with DBA authority
- Issue the command: @ps_oracle.sql
The @
symbol is required in the command.
- Exit Oracle SQL Plus
Administering the J2EE Resources
- Start the WebSphere Application Server
- Point your browser to the WebSphere Application Server Administrative Console:
http://localhost:9090/admin
- Remove the Pet Store preconfigured Datasource:
- Expand Resources > JDBC Drivers > idbJdbcDriver and
click Data Sources
- Delete Petstore IDB Datasource
- Add the Oracle JDBC Driver:
- Expand Resources and click JDBC Drivers
- Click New
- From the drop down menu, click Oracle JDBC Driver
- Click Next
- Set the Server Class Path to point to the JAR files containing the driver
classes, which in a default Oracle installation would be:
- On Windows:
ORACLE_HOME\ora81\jdbc\lib\classes12.zip
where: ORACLE_HOME is the path where Oracle
V8.1.7 is installed, as shown in the ORACLE_HOME environment variable
for the Oracle administrative user. Check with your Oracle DBA if
you are unsure about the Oracle installation.
- On UNIX:
ORACLE_HOME/jdbc/lib/classes12.zip
where: ORACLE_HOME is the path where Oracle
V8.1.7 is installed, as shown in the ORACLE_HOME environment variable
for the Oracle administrative user. Check with your Oracle DBA if
you are unsure about the Oracle installation.
- On Linux:
ORACLE_HOME/jdbc/lib/classes111.zip
where: ORACLE_HOME is the path where Oracle
V8.1.7 is installed, as shown in the ORACLE_HOME environment variable
for the Oracle administrative user. Check with your Oracle DBA if
you are unsure about the Oracle installation.
- Use the following values for the remainder of the Properties fields.
You can leave any values not specified below blank:
Name: |
Oracle JDBC Driver |
Description: |
Oracle JDBC Driver |
Implementation Classname: |
oracle.jdbc.pool.OracleConnectionPoolDataSource |
- Click OK for the new JDBC driver
- Add the Pet Store Datasource:
- Click Oracle JDBC Driver > Data Sources
- Click New
- Use the following values. You can leave the remaining values blank:
Name: |
PetStoreDatasource |
JNDI Name: |
ps/PetStoreDatasource |
Default User ID: |
"estoreuser"
You
must include the double quotes in the field. |
Default Password: |
"estore"
You
must include the double quotes in the field. The field shows an
asterisk (*) symbol for each character entered. |
- Click OK
- Click the PetStoreDataSource you just created
- Under Driver Specify Settings, click Properties
- Click New
- Enter the following values in the property sheet. You can leave the
remaining values blank:
Name: |
URL |
Type: |
java.lang.string |
Value: |
jdbc:oracle:thin:@hostname:port:databaseName
where:
- hostname is the Oracle Server host name or IP address
- port is the port number on which Oracle is listening.
Port 1521 is the default.
- databaseName is your database name
|
- Click OK for the Resource Properties: URL
- Click OK for the Resource Properties
- Click OK for the Data Sources
- Click the Configuration needs to be saved link at the
top
- Click OK to save the configuration
- Add the Pet Store Mail Session:
Add a JavaMail session to the default mail provider. Pet Store only sends
outgoing mail, so only the mail transport needs configuration.
- Expand Resources > Mail Providers > Default Mail Provider
> Mail Sessions and click New
- Enter the following values in the property sheet on the New Mail Sessions
page. You can leave the remaining values blank:
Name: |
PetStoreMail |
JNDI Name: |
ps/PetStoreMailSession |
Mail From: |
Enter your e-mail user ID, for example: john.smith@mycompany.com |
Mail Transport Host: |
Enter the name of your mail server host, for example: mail.mycompany.com |
Mail Transport Protocol: |
Enter your protocol, for example: smtp |
Mail Transport User: |
Enter your user name, for example: john.smith |
Mail Transport Password: |
Enter the password for the user |
- Click OK
- Enable application-level visibility so that .wars and EJB .jars
can find classes in other .wars and EJB .jars:
- Expand Nodes > Your Node > Application Servers and click
Default Server
- Change Module Visibility to Application
- Click OK
- Save your configuration and exit
- Shut down the WebSphere Application Server
Installing the Application
The petstore.ear file comes preinstalled and enabled to use IDB.
Uninstall the petstore.ear file with IDB, to enable Oracle. Issue
the following command from a command prompt, to remove this EAR:
- On Windows:
SEAppInstall -uninstall petstore -delete true
- On UNIX:
./SEAppInstall.sh -uninstall petstore -delete true from the
/opt/WebSphere/AppServer/bin subdirectory
Now you are ready to install. Issue the following command:
- On Windows:
SEAppInstall -install <WAS_ROOT>\installableApps\petstore\petstore.ear
-ejbdeploy false -precompileJsp false -interactive false
- On UNIX:
Issue this command from /opt/WebSphere/AppServer/bin:
./SEAppInstall.sh -install <WAS_ROOT>/installableApps/petstore/petstore.ear
-ejbdeploy false -precompileJsp false -interactive false
Running the Application
- Start the WebSphere Application Server
- Run the Pet Store Sample
Using the
back button on your browser can cause problems. Therefore, it is not recommended
with Pet Store. If you would like to return to a previous page in the application,
use the links in the Pet Store application. For example, to return to the
Main page, click on the Pet Store banner. See the official Pet Store documentation
from Sun,
for further details.
You must enable
cookies in your browser to support Pet Store security.
Use the following instructions to uninstall the Pet Store application:
- Stop the WebSphere Application Server
- Issue the following command:
- On Windows: SEAppInstall -uninstall petstore
- On UNIX: ./SEAppInstall.sh -uninstall petstore from
the /opt/WebSphere/AppServer/bin subdirectory
- Drop the Pet Store database:
- From an Oracle SQL Plus window, issue the following commands:
- DROP TABLESPACE PETSDB INCLUDING CONTENTS;
- DROP USER "estoreuser" CASCADE;
You must include the double quotes and semi-colon in the
commands.
- Delete the PETSDB.dbf file that was made during the database
creation step
- Remove the datasource:
- Start the WebSphere Application Server
- Point your browser to the WebSphere Application Server Administrative
Console:
http://localhost:9090/admin
- Locate your Pet Store data source and mail session, then delete them
- Save your configuration
- Stop the WebSphere Application Server