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 has already been modified for you. The following changes were 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 class-path 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 petstore.ear file
- Expand petstore -> EJB Modules -> Customer
Component -> Entity Beans -> TheOrder ->
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 select Environment Entries
- Change the value of the sendMailConfirmation parameter from false to
true
- Click Apply
- Exit AAT (File -> Save, Exit)
Deploying the Application
Creating and Populating the Database
Locate the ps_oracle.sql file in the installableApps\petstore
directory. This .sql file creates the required tables and populates
them 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
Note: 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 Pet Store preconfigured Datasource:
- Expand Resources -> JDBC Drivers -> idbJdbcDriver -> Data Sources
- Delete Petstore IDB Datasource
- Add the Oracle JDBC Driver:
- Expand Resources
- Right-click JDBC Drivers and select New
- From the drop down menu, select Oracle JDBC Driver
- Click Next
- Set Server Class Path to point to the jar files containing the driver
classes. In a default Oracle installation, it would be:
- On Windows:
ORACLE_HOME\ora81\jdbc\lib\classes12.zip
where ORACLE_HOME is the path
where Oracle 8.1.7 is installed as shown in the ORACLE_HOME environment
variable for the Oracle Administrative user. Check with your Oracle
DBA Administrator if you are unsure about the Oracle installation.
- On UNIX:
ORACLE_HOME/jdbc/lib/classes12.zip
where ORACLE_HOME is the path
where Oracle 8.1.7 is installed as shown in the ORACLE_HOME environment
variable for the Oracle Administrative user. Check with your Oracle
DBA Administrator if you are unsure about the Oracle installation.
- On Linux:
ORACLE_HOME/jdbc/lib/classes111.zip
where ORACLE_HOME is the path
where Oracle 8.1.7 is installed as shown in the ORACLE_HOME environment
variable for the Oracle Administrative user. Check with your Oracle
DBA Administrator if you are unsure about the Oracle installation.
- Set Name: Oracle JDBC Driver
- Set Description: Oracle JDBC Driver
- Set Implementation Classname: oracle.jdbc.pool.OracleConnectionPoolDataSource
- Click OK for the new JDBC driver
- Add the Pet Store Datasource:
- Expand Oracle JDBC Driver and click Data Sources
- Click New
- Set Name: PetStoreDatasource
- Set JNDI Name: ps/PetStoreDatasource
- Set Default User: "estoreuser"
Note: You must include the double quotes in the field.
- Set Default Password: "estore"
Note: 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, select Properties
- Select New
- Set Name: URL
- Set Type: java.lang.string
- Set Value: jdbc:oracle:thin:@hostname:port:databaseName
where:
- hostname is the Oracle Server hostname or IP address.
- port is the port number Oracle is listening on. (Port 1521
is the default.)
- databaseName is your database name.
- Select OK for the Resource Properties:URL
- Select OK for the Resource Properties
- Select OK for the Data Sources
- Select Configuration needs to be saved link at the top
- Select OK for save 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.
- Go to Resources -> Mail Providers ->
Default Mail Provider -> Mail Sessions. Click New
- On the New Mail Sessions page, enter the following:
Use these values in the property sheet (the rest can be left 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: Select 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 -> 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 pre-installed and enabled to use IDB. In
order to enable Oracle, the petstore.ear with IDB must be uninstalled.
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 /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
Note: Using the back button on your browser is not recommended
with Pet Store, and can cause problems. 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.
Cookies must be enabled in your browser to support Pet Store security.
- Stop the WebSphere Application Server
- Issue the following command:
- On Windows: SEAppInstall -uninstall petstore
- On UNIX: ./SEAppInstall.sh -uninstall petstore
from /opt/WebSphere/AppServer/bin subdirectory
- Drop the Pet Store database:
- From a Oracle's SQL Plus window, issue the following commands:
- DROP TABLESPACE PETSDB INCLUDING CONTENTS;
- DROP USER "estoreuser" CASCADE;
Note: You must include the double quotes and semi-colon in the commands.
- Erase 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 remove them
- Save your configuration
- Stop the WebSphere Application Server