Stateful Simple EJB Cart Sample Application |
Stateful Simple EJB Cart Sample Application
This document describes how to utilize the Stateful Simple EJB Cart sample application in conjunction with the Application Server.This sample application document contains the following sections:
- Overview
- Compiling and Assembling the Sample Application
- Deploying the Sample Application
Overview
The cart sample demonstrates the use of stateful session bean. Typical use of a stateful session bean is a shopping cart. The session bean (CartEJB) represents a shopping cart in an online bookstore. The bean's client may add a book to the cart, remove a book, or retrieve the cart's contents. The sample is comprised of an EJB and a client.When you try to run the client using appclient, it should look as follows:
> appclient -client stateful-simpleClient.jar -name CartClient -textauth
Caught a BookException: Alice in Wonderland not in cart
Compiling and Assembling the Sample Application
To 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.To rebuild the entire application from scratch, follow these steps:
- Compile and Assemble Web Application. For example:
- Execute asant under <install_dir>/samples/ejb/stateful/apps/simple
- The default target core will be executed to rebuild the .jar and .ear files.
- Deploy the application.
- Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.
- Clean the web application project area. For example:
- Execute asant clean
- This will remove the sample application assemble and build directories.
Deploying the Sample Application
A pre-built stateful-simple.ear file is supplied with the application server installation. The pre-built stateful-simple.ear file is an Enterprise Archive (.ear) file that contains, the EJB .jar file and the web application .war file of the application. Within each file resides the XML deployment descriptor files, application class files, and other content required by the application. You can use the pre-built .ear file to deploy the application. If you want to experience compiling and assembling the application from scratch, follow the instructions in Compiling and Assembling the Sample Application.To deploy the application, the administrative server needs to be running. To start the administrative server if it is not already started, do one of the following, depending on your oeprating system.
Select one of the following approaches to deploying the application:
- UNIX
- Execute <install_dir>/bin/asadmin start-domain domain1
- Windows
- Start->Programs->Sun Microsystems->J2EE 1.4 SDK->Start Default Server
- Command Line-based Deployment describes how to manually register the application in the 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 Admin GUI to import and deploy the sample application.
Command Line-based Deployment
Command Line Interface is the fastest means of deploying the application. If you want to deploy through a GUI tool, follow the instructions for GUI Based Deployment. CLI deployment of the application can be done by either the Using the asant script or by Using the asadmin command.
- Go to the src directory of the sample. For example:
- cd <install_dir>/samples/ejb/stateful/apps/simple
- Run asant using deploy task. For example:
- %asant deploy
- This also registers the resources to the application server.
Note You must run asant undeploy before redeploying this sample. This will ensure that all modules are undeployed and the resources are disabled.
The deployment process involves the following operations:
- Go to the root of the sample directory. For example:
- cd <install_dir>/samples/ejb/stateful/apps/simple
- Execute asadmin to deploy application to the local application server instance. For example:
- asadmin deploy --user <username> --password <password> --host <host> --port <admin-port> stateful-simple.ear
If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
- Authenticates against the local application server's administrative server
- The EAR file is transferred to the administrative server
- The administrative server begins the registration process:
GUI Based Deployment
Since a pre-built Enterprise Archive (.ear) file for the sample application is included with the application server, you can use the Admin GUI to quickly read in the .ear file and deploy it to the application server.
- Start the admin server if it is not already started. Here are the commands for each platform:
- Unix - Execute the <install_dir>/bin/asadmin start-domain domain1 command.
- Windows - Click "Start->Programs->Sun Microsystems->J2EE 1.4 SDK->Start Default Server" command.
- Open the .ear file.
- Start Admin GUI, by entering URL http://localhost:<admin.port>/asadmin in browser. See replacing "localhost" and <admin.port> note here to determine correct values to use for your environment
- You are prompted to supply the user name and password of the application server. Enter correct values for your installed application server for "User Name:" and "Password:" input fields, then click on the "Login" button.
- In the left-hand frame, click Applications-->Enterprise Applications icon in the tree.
- In the right-hand frame, click on the "Deploy..." button.
- Choose the file to be deployed by clicking on the "Browse..." button, and navigate to select component to deploy (stateful-simple.ear).
- In the browse dialog, click on the "OK" button.
- In the right-hand frame, click on the "Next" button.
- In the right-hand frame, click on the "OK" button. (Optionally fill in remaining values for application to be deployed)
- In the left hand pane, you will see the newly deployed module's icon in the tree. In the right hand pane you will also see the component listed as deployed.
Verifying Deployment
As an optional step, you can use the Application Server Administration GUI Tool to verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.To verify the registration of the application, follow these steps:
- Execute the command asadmin list-components to look at applications deployed with a server instance. For example:
- asadmin list-components --user <username> --password <password>
- Alternately, you may navigate the Admin tool GUI to the following:
- Applications-->Enterprise Applications.
- On the left frame, Click on Enterprise Applications to display list of applications deployed on server.
Generating Javadocs
To better understand the sample application source code, you can refer to the related javadocs.To generate javadocs run one of the following commands:
After javadocs are generated, you can access them at <install_dir>/samples/ejb/stateful/apps/simple/javadocs/index.html
Running the Sample Application
There is no web interface for this sample. Please follow the command line interface instructions to run the sample.
Running the Sample using the client interface
Running the sample using client interface is a two step process:
- Go to the directory where the sample has been deployed. For example:
- cd <install_dir>/domains/<domain_name>/applications/j2ee-apps/stateful-simple/
- Run appclient using the following instructions:
- appclient -client stateful-simpleClient.jar -name CartClient -textauth
- You will see the following output:
- ...
- The Martian Chronicles
- 2001 A Space Odyssey
- The Left Hand of Darkness
- Caught a BookException: Alice in Wonderland not in cart
Troubleshooting
- Make certain that you run the asant undeploy command before redeploying this sample to make sure that all modules are undeployed properly.
- Although the war, ear, context-root and servlet alias names in this sample are all "stateful-simple", it is not necessary that it be so. The application will work as expected if the names of each of these attributes is unique. Rebuild the application after changing the context-root (in application.xml), the servlet alias (in web.xml) and the war and ear names, redeploy and test the sample to confirm this.
- If you encounter problems when running the application, review the log files at <install-dir>/domains/<domain_name>/logs/server.log to learn what went wrong.
Copyright © 2004 Sun Microsystems, Inc. All rights reserved.
Last
Updated March 6, 2004