Sun Java System logo
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 Sun Java  System Application Server Enterprise Edition 7 2004 Q2.This document also describes how to test the high availability feature in appserver for Stateful session bean with web client and rich client.

This sample application document contains the following sections:

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 servlet. The appserver makes the Cart EJB highly available. If one server goes down the conversational state (i.e the cart contents) is migrated transparently to another available server instance in the cluster.
 

 
 

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:

  1. Compile and Assemble Web Application. For example:
  2. Execute asant under <install_dir>/samples/ee-samples/sfsbfailover/simple/src/
    The default target core will be executed to rebuild the .jar and .ear files.
  3. Deploy the application.
  4. Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.
  5. Clean the web application project area. For example:
  6. Execute asant clean
    This will remove the sample application assemble and build directories.

     
Deploying the Sample Application

A pre-built sfsbFailover.ear file is supplied with the application server installation. The pre-built sfsbFailover.ear file is an Enterprise Archive (.ear) file that contains, the EJB .jar file,  web application .war file and the client jar 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: 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.
 
 

Using the asant script
 

  1. Go to the src directory of the sample. For example:
  2. cd <install_dir>/samples/ee-samples/sfsbfailover/simple/src
  3. Run asant using deploy task. For example:
  4. %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.

     
Using the asadmin command
 
  1. Go to the root of the sample directory. For example:
  2. cd <install_dir>/samples/ee-samples/sfsbfailover/simple
  3. Execute asadmin to deploy application to the local application server instance. For example:
  4. asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> sfsbFailover.ear
The deployment process involves the following operations: 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 Deployment

To deploy the EAR file, follow these steps:

  1. Log in to the web-based administration tool from the browser.

  2.  
  3. Navigate as follows:
  4. Application Server Instances --> <server instance> --> Applications --> Enterprise Applications
  5. Click Deploy.

  6. Click Browse to locate the sfsbFailover.ear file.
  7. The ear file is located under <install_dir>/samples/ee-samples/sfsbfailover/simple.
  8. Click OK.

  9. Enter sfsbFailover  in the Application Name field.

  10. Click OK.

  11. Click the sfsbFailover  link to verify that the application is deployed.

  12.  
Verifying Deployment

As 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, follow these steps:

  1. Execute the command asadmin list-components to look at applications deployed with a server instance. For example:
  2. asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>
  3. Alternately, you may navigate the Admin tool GUI to the following:
  4. App Server Instances>server1>Applications.
  5. On the left frame, Click on Enterprise Apps 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:

asant javadocs

or

asant all

After javadocs are generated, you can access them at <install_dir>/samples/ee-samples/sfsbfailover/simple/javadocs/index.html
 
 

Running the Sample Application


1.   Web-based client.

To see the failover of the SFSB happening, configure your loadbalancer in the web server for the cluster comprising multiple appserver instances.
This is needed to make request independent of which server instance is serviceing the request.
From your browser, access the application page from http://host:port/sfsbFailover, where the host and port are of webserver.

 

Screen 1
 
 
 



You now enter the sfsbFailover bookstore . Enter the name of a book and add the book to your cart by clicking on 'Add Book To Cart'.
Similarly, you can remove a book from your cart. The updated contents of the cart are shown at the bottom of the page.

Screen 2


To test the failover of the SFSB happening,  add few books to the cart. The contents of the cart are shown. Then stop the appserver instance which served the previous requests.Add another book to your cart. The request is now served by another available server instance in the cluster. The conversational state of the session bean is transparently migrated to this server.You can see book is added to the the original contents of the cart.You can also test the failover behaviour by removing the book from the cart.



2.  RMI/IIOP-based client with ACC.

The Java client will be run on the same machine where the Application Server is running.

3.   Local or remote RMI/IIOP-based client without ACC.

The java client is executed without using the interface of Application Client Container. It can be executed on the local machine (ashost) or a remote machine. The client application runs from the command line, i.e. where As a complete example for the command, it looks like the following for this sample, You will see interactive console, which helps you to also test the high availability of the SFSB, InitialContext, Home reference and remote reference.After creating the InitialContext the interface stops for user to press enter. The user can stop the server where the InitialContext was created and enter, the refernce is failedover to another available server instance. The user can test the failover bahaviour for home reference, remote reference as well in the same way.

Troubleshooting
 

Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated August 21, 2002