![]() |
Duke's Bookstore Sample Application for Enterprise Edition |
Duke's Bookstore Sample Application for Enterprise Edition
This document describes how to utilize the Duke's Bookstore sample application in conjunction with Sun Java (tm) System Application Server Enterprise Edition 7 2004Q2.
This sample application document contains the following sections:
Overview
- Overview
- Compiling and Assembling the Application
- Deploying the Sample Application
- Using Oracle Database
- Running the Sample Application
- Troubleshooting
The Duke's Bookstore sample application illustrates the tasks involved in programming using Java Server Pages (JSP). This application allows users to retrieve available books from a database table, displays details of the book, add and remove books to a shopping cart and check out the books. The Duke's Bookstore implements the Model-View-Controller design pattern and database helper object for accessing database.
Compiling and Assembling the Application
This section contains instructions to build and assemble the Duke's Bookstore sample application from scratch using Command Line Interface (CLI). See the Sample Application Build Facility document for details on using asant facility to quickly perform these tasks.
- To rebuild the sample as J2EE module (war), do the following:
- Go to the ee-samples/dukesbookstore/src directory
- Execute the command $AS_HOME/bin/asant
The default target core will be executed to compile java files and rebuild the WAR file.
- To build the sample as J2EE application (ear), do the following:
- Go to the ee-samples/dukesbookstore/src directory
- Execute the command $AS_HOME/bin/asant ear
- Deploy the application.
- Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.
Deploying the Sample Application
- Clean the web application project area using the asant clean command. For example:
- $AS_HOME/bin/asant clean
In this section, you will learn how to deploy the Duke's Bookstore sample application.Select one of the following approaches to deploying the application:
- Command-Line based Deployment describes how to manually register the application in Sun Java (tm) System Application Server using a Command Line Interface (CLI). This is the fastest means of deploying the sample application.
- GUI-based Deployment describes how to use the Sun Java (tm) System Application Server Administration Tool to deploy the sample application.
Command-Line based DeploymentSince a complete WAR file is supplied, the fastest means of setting up the application is to use the command line utilities described in this section.
The pre-built dukesbookstore.war file is a Web Archive (WAR) file of the application.
Deploying the pre-built dukesbookstore.war file is simple. Deploy either Using the asant script or by Using the asadmin command.
Please start your database server, if not started.
Execute the following steps:
If you choose to use the PointBase database, more details see Using PointBase with Samples.
- Go to the src directory of the sample
- cd $AS_HOME/samples/ee-samples/dukesbookstore/src
- Run asant using deploy task
- $AS_HOME/bin/asant deploy
- It is an interactive command that may prompt you for the admin-server host, admin-server port, admin user name, admin password, and appserv instance. This also registers the resources to the Sun Java (tm) System application server.
If you choose to use the Oracle database, see Using Oracle database.
Using the asadmin commandWhere <admin_username> is application server admin user name, <admin_password> is the admin password, <host> is the machine on which the application server is installed, <adminserver_port> is admin server port of the application server, and <instance_name> is the application server instance name (e.g. server1).
- Go to the root of the sample directory
- cd $AS_HOME/samples/ee-samples/dukesbookstore
- Execute asadmin to deploy application to the local application server instance. For example:
- $AS_HOME/bin/asadmin deploy -u <admin_username> -w <admin_password> -H <host> -p <adminserver_port> --type web --name dukesbookstore --instance <instance_name> dukesbookstore.war
If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
GUI-based DeploymentSince a pre-built Web Archive (WAR) file for the sample application is included with the application server, you can use the Sun Java (tm) System Application Server Administration Tool to quickly deploy it to the Application Server.
- From your web browser, access the Sun Java (tm) System Application Server by entering the URL. For example:
- http://<server-host>:<admin-port>
- Enter the server administrator's username and password to access the admin server.
- On the left panel, navigate the tree by clicking on the following:
- App Server Instances->server1->Applications->Web Apps
- On the right panel, click on the Deploy button.
- Enter the File Path to select the file (from disk) to be deployed (dukesbookstore.war)
- Click OK.
- Enter the application name as dukesbookstore and context root as dukesbookstore
- Click OK
If the deployment processes correctly, you will see the original panel displaying the dukesbookstore application as deployed.
Verifying DeploymentAs an optional step, you can use the Sun Java (tm) System 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 display applications deployed with a server instance.
$AS_HOME/bin/asadmin list-components -u <admin_username> -w <admin_password> -H <host> -p <adminserver_port> <instance_name>
For example:
$AS_HOME/bin/asadmin list-components -u admin -w adminadmin -H west -p 4848 server1You should see output similar to what is displayed below:
- TradeSample <application>
- dukesbookstore <web>
There are no standalone EJB modules
There are no connector modules
Undeploying the Sample ApplicationTo undeploy the application, do the following:
- Go to the ee-samples/dukesbookstore/src directory
- Execute the command asant undeploy
- To undeploy the jdbc datasource, execute the command asant undeploy-sql
- Reconfigure the server instance.
$AS_HOME/bin/asadmin reconfig -u <admin_username> -w <admin_password> -H <host> -p <adminserver_port> <instance_name>
Before run the sample application, you must first do the following:JDBC connection pool
- Please start your database server, if not started.
- Run the command asant setup_pb if you are going to use PointBase that was bundled with the Platform Edition and Standard Edition. To run the sample on Oracle please refer to Using Oracle database section below.
- OR do the following steps to register resources if you already have a connection to any database:
asadmin create-jdbc-connection-pool --host <admin host> --port <admin port> --user <user> --password
<password> --instance <server instance name> --datasourceclassname <datasource classname> --property
User=<database username>:Password=<database password>:<url-property>="<database jdbc url>" bookstorePoolIn case of PointBase, please use DatabaseName as <url-property>. In case of Oracle, please use URL as <url-property>. You will need to escape ":" and "/", in <database jdbc url> . An example of <database jdbc url> is
"jdbc\:pointbase\:server\:\/\/localhost\:9092\/sun-appserv-samples".JDBC resource
- JNDI name should be "jdbc/BooksDB" as the name is used in the deployment descriptor
asadmin create-jdbc-resource --host <admin host> --port <admin port> --user <user> --password <password>
--instance <server instance name> --connectionpoolid bookstorePool jdbc/BooksDB
Note: The PointBase database server will not be bundled with the Enterprise Edition release. Therefore, you can either use Oracle or PointBase, you can create the database from scratch using sql files in src/sql directory to manually create schema and populate data: use books_pb.sql for PointBase or books.sql for Oracle database.
For more information on using PointBase, please refer to the Using PointBase with the Samples document.
Using Oracle databaseTo run sample with Oracle database, please follow the steps outlined below. For more details see (How to run samples with Oracle database server) document.
Running the Sample Application
- For more information, please refer to General settings of the oracle document.
- Create an RDBMS user
- cd <install_dir>/samples/ee-samples/dukesbookstore/src/sql
- sqlplus to oracle as system user
- SQL> @createUser.sql
- exit sqlplus
- Create and the Product RDBMS Tables
- cd <install_dir>/samples/ee-samples/dukesbookstore/src/sql
- sqlplus to oracle as bookstore user
- SQL> @books.sql;
- Register JDBC Driver
Make sure that JDBC driver zip/jar files are in classpath-suffix attribute of java-config element in server.xml of the instance running this product application. You may like to edit this file if necessary and make sure that the server.xml is also copied to backup directory. Or, you can specify the location of the driver files in the Classpath Suffix field in the application server's configuration. Start the administrative console and access the application server instance's JVM Settings -> Path Settings area to make this change. Then restart the server instance.
- Add the following target to build.xml.
<target name="setup_ora" depends="setup_env, deploy_jdbc_resource_ora_common, reconfig"/>
- Create jdbc connection pool and Data source. To do so, run
asant setup_ora -Ddb.host=[db_hostname] -Ddb.port=[db_port] -Ddb.sid=[sid]
- Deploy the application. Use asant deploy.
In order to run the sample application, you must first do the following:You are now ready to run the sample application by doing the following.
- Start your database server
- Register resources if you have not done so
- Compile, Assemble and Deploy the application as described in the previous sections Compiling and Assembling the Application, and Deploying the Sample Application.
The following images are from running the sample.
- On your browser go to the url : http://<host>:<port>/dukesbookstore/enter
![]()
Figure 1 - Duke's Bookstore: "Start Shopping" link
![]()
Figure 2 - Duke's Bookstore: Books Catalog
![]()
Figure 3 - Duke's Bookstore: Shopping Cart
![]()
Figure 4 - Duke's Bookstore: Cashier
Generating javadocsTo better understand sample application source code, you may refer to the related javadocs.
To generate javadocs, run the following command from .../ee-samples/dukesbookstore/src:
asant javadocs
After javadocs are generated, you may access them at samples/ee-samples/dukesbookstore/javadocs/index.html.
- If you encounter problems when running the application, review the log files at <install-dir>/domains/domain1/<server-instance>/logs/server.log to learn what exactly went wrong.
- Check to see if the database is running.
- To reset your database, run the command asant sql if using PointBase
- To redeploy the sample, please undeploy the sample first. Use the commands asant undeploy, asant clean and then asant all.
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.