![]() |
Java TM Pet Store 1.3 Sample Application |
Java TM Pet Store 1.3 Sample Application
This document describes how to utilize the Java TM Pet Store sample application in conjunction with Sun ONE Application Server version 7.
This sample application document contains the following sections:
Overview
- Overview
- Compiling and Assembling the Application
- Deploying the Sample Application
- Running the Sample Application
- Configuring for use with the Oracle Database
- Troubleshooting
Java TM Pet Store 1.3 is the Sun J2EE sample application that demonstrates many facets of the J2EE specification. See the Architectural Overview document for more information regarding the design and implementation of this popular J2EE application. The Blueprints area of http://java.sun.com offers many resources on the design of J2EE applications.The Java Pet Store Demo consists of the following high level components:
- The Storefront presents the main user interface in a Web front-end. Customers use the Storefront to place orders for pets.
- The Order Processing Center (OPC) receives orders from the Storefront. Any time the database is updated, the Supplier notifies the OPC about the changes to the inventory. The OPC examines these changes to see if it can fulfill any orders that it previously could not. If it can fullill an order, it will mark the order as completed.
- The Supplier fulfills orders from the OPC from inventory and invoices the OPC. The supplier and its inventory are managed using a simple Web interface.
- The Admin presents the administrator interface in a JFC/Swing front-end. Administrators use the Admin to examine pending orders and approve or deny them. An order appears as pending if its total value is greater than $500.
In order to successfully deploy and run the Pet Store 1.3 sample application, several resources need to be setup with the Application Server. These resources include:
The build scripts provided will automatically register all the above resources with Application Server. The default values for these resources are stored in src/build.properties. Edit this file if you would like to change the default values.
- JDBC resources
- JDBC connection pools
- Persistence manager factories for the various components of Pet Store
- JMS resources for queue and topic connection factories
- Java Mail resources to setup e-mail.
Note The admin password needs to be changed based on your selection during Application Server installation.
The PointBase database server is automatically populated with all the necessary data for the Pet Store sample application when it is started. Start the PointBase database server by running one of the following scripts, depending on your operating system:
For more information on using PointBase please refer to the Using PointBase document.
- For Solaris:
- <install_root>/pointbase/server/bin/StartServer.sh
- For Windows 2000:
- <install_root>/pointbase/server/bin/StartServer.bat()
If you prefer to re-create the database from scratch, you can use the sql files in src/sql to manually create schema and data in your PointBase server.
For the Pet Store Admin application, you need to install Java Web Start on your client machine You can download Java Web Start from http://java.sun.com/products/javawebstart
Note Java Web Start must be configured to use JRE 1.4 for the Pet Store Admin Application. Download JRE 1.4 for Windows (or your platform) on your client machine. You can configure Java Web Start 1.0.1 to work with JRE 1.4 by either specifying the JRE (1.4) while installing Java Web Start or after installing WebStart, change the configuration in File->Preferences->Java and changing the path for javaw.exe
Compiling and Assembling the Application
This section contains instructions to build and assemble the Pet Store Demo application.
Note You may skip this step and go to Deploying the Sample Application using the pre-built EAR files located under <install_root>/samples/petstore1.3._01/
Deploying the Sample Application
- Compile and assemble the application.
- Execute the command asant core under <install_root>/samples/petstore1.3._01/src
- This will compile all sources and assemble the following four modules as EAR files:
- petstore
- admin
- opc
- supplier
- Deploy the application.
- After compiling the sources and assembling the ear files, you may proceed to Deploying the Sample Application. Steps 4 and 5 are optional.
- Clean the application project area (optional).
- Execute the command asant clean to remove all the files generated in Step 3.
- Generate javadocs (optional).
- Execute the command asant javadocs under <install_root>/samples/petstore1.3._01/src
- Javadocs will be located under <install_root>/samples/petstore1.3._01/javadocs
To deploy the application, do the following:Execute the command asant deploy under <install_root>/samples/petstore1.3._01/src
This will deploy the EAR files for the four modules of Pet Store (petstore.ear, opc.ear, supplier.ear, and petstoreadmin.ear). These file are located under <install_root>/samples/petstore1.3._01/. Restart the appserver instance after doing this.
As an optional step, you can use the Sun ONE Application Server Administration Tool to verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.
To verify the registration of the application, do the following:
Execute the command asadmin list-components to look at applications deployed with a server instance. For example:
<install_root>/bin/asadmin list-components -u <username> -w <password> -H <host> -p <port> <server instance name>
You will see the four Pet Store applications listed:
Customizing Pet Store
- admin
- petstore
- opc
- supplier
You could deploy each of the modules separately if you made code changes in any of the modules. In order to do that, you need to recompile and re-assemble the EAR files first. This can be done using either of the following: <install_root>/samples/petstore1.3._01/src/build.xml or
build.xml in individual module. lFor example, <install_root>/samples/petstore1.3._01/src/apps/admin/src/build.xml
Note Before redeploying, you must first execute the command asant clean in order to clean up existing files resulting the intital deployment.
Running the Sample Application
In order to run the sample application, you must first do the following:Accessing Pet Store Application
- Deploy the application
- Start your PointBase database server
- Append Pet Store related entries to the keyfile
- Configure Java Web Start if you are planning to run the Pet Store Admin application.
- From your browser, access the application launch page at: http://<server>:<port>/petstore/index.jsp
- Click Enter the Store to access the Pet Store end-user entry screen as seen in displayed in Figure 1.
![]()
Figure 1 Launch page
- Click the Sign In first button to create your user account as seen in Figure 2.
![]()
Figure 2 Sign in prompt
- Click on Create New Account to edit your account information as seen in Figure 3.
![]()
Figure 3 Create user window
- Once the account is created, you can browse the catalog and select items you want to buy as seen in Figure 4.
![]()
Figure 4 Product identification screen
- Click on Add to Cart to add items to your cart. You can view and manage your shopping cart as seen in Figure 5.
![]()
Figure 5 Shopping cart screen
- Click Proceed to Checkout.
- The Account Page will de displayed once again. You will have another chance to edit the account information.
- Click Submit to see the Order completion page as displayed in Figure 6.
![]()
Figure 6 Order completion page
Note You could browse the catalog without signing in. However, the application will request that you to sign in before you check out your order.
Running the Sample Application
- From your browser , access the application launch page at: http://<server>:<port>/rcvr
- Login in as rcvr and you will see Receiver's home page as seen in Figure 7.
![]()
Figure 7 Receiver Sign in page
- Click on Display Inventory from the Receiver's home page to manage the inventory as seen in Figure 8.
![]()
Figure 8 Inventory update page
- Java Web Start must be set up in order for the Admin application to run.
- In case you haven't installed Java Web Start yet, refer to the directions in Setting up the environment.
- From your browser, access the the Admin application displayed in Figure 9 at: http://<server>:<port>/admin
![]()
Figure 9 Admin application
- Login in as jps_admin
- Click Launch Rich Client. This will bring up the admin client interface outside your browser as seen in Figure 10. The admin application is a Java client that uses JFC/Swing for UI.
![]()
Figure 10 Estore Admin page
Configuring for use with the Oracle Database
The product application requires the following database setup prior to running:
Ensure Database Requirements are Met
TroubleshootingSee the Sun ONE Application Server Release Notes for database version requirements. The Product sample includes schema script for Oracle.
Create an RDBMS User
cd <install_root>/samples/petstore1.3._01/src/sql
sqlplus to oracle as system user and create 3 users called petstore, opc, supplier.
SQL> @createUser.sql
Create and Populate the Product RDBMS Tablescd <install_root>/samples/petstore1.3._01/src/sql
Register JDBC Driversqlplus to oracle as "petstore" user
SQL> @petstoredb.sql;
sqlplus to oracle as "opc" user
SQL> @opcdb.sql;
sqlplus to oracle as "supplier" user
SQL> @supplierdb.sql;
exit sqlplus
Please refer to Using Oracle with samples for registering Oracle Driver to Sun ONE Application Server.Create a new Oracle JDBC Connection Pool
If you have followed the instructions for Compiling, Assembling and Deploying the Application against the PointBase server then:Change to the directory <install_root>/samples/petstore1.3._01/src
Execute the command asant undeploy
Edit <install_root>/samples/petstore1.3._01/src/build.properties file with correct oracle host(db.host), port(db.port)and sid (db.SID) values
Execute the command asant deploy-ora
And then restart the server instance.Change to the directory <install_root>/samples/petstore1.3._01/src
If you have already deployed application for PointBase, do the following:
Execute the command asant undeploy
Execute the command asant deploy-ora -Ddb.host=<host> -Ddb.port=<port> -Ddb.sid=<sid>
Apply changes and restart server.
Otherwise, do the following:
Execute the command asant deploy-ora -Ddb.host=<host> -Ddb.port=<port> -Ddb.sid=<sid>
Apply changes and restart server.The db.host, db.port, db.sid can also be specified in <install_root>/samples/petstore1.3._01/src/build.properties.
Rerun the Sample Application
You may now run the application again using the steps under Running the Sample Application section.
Some Known Issues:
- If you encounter problems when running the application, review the log files at <install-root>/domains/<domain-name>/<server-instance>/logs/server.log to learn what exactly went wrong.
- If you encounter problems running the Admin application, make sure that the Java WebStart is configured correctly as described inthe section Running the Sample Application.
- If you encounter errors while deploying the application, make sure that your admin password is set correctly in <install-root>/samples/common.properties.
- If you make changes to the application, you can use the build.xml in that specific module to rebuild the EAR files. Your changes will be effective after you redeploy the EAR files.
- From petstore administrator application, approving or denying an order, and clicking on commit causes the status to return to pending. User needs to click on Refresh Data button, to see the correct status.
- The repopulate link does not work for Oracle. Clicking on the link populates the inventory data but not the catalog data. User needs to populate it using petstoredb.sql.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.