Sun Java System logo
CMP Roster Sample Application for Enterprise Edition

 
CMP Roster Sample Application for Enterprise Edition
 

This document describes how to utilize the CMP Roster sample application in conjunction with Sun Java (tm) System Application Server Enterprise Edition 7 2004Q2.

This sample application document contains the following sections:

Overview

The CMP Roster sample application is a set of CMP 2.0 EJBs with Local interfaces. This application demonstrates the use of container managed persistence and relationships between entity beans. The application allows user to insert data into database for the first time run or after data has been removed from the database, select different data displaying selections, invalidate current HttpSession, and remove data from database.  To demonstrate the high availability of servers in the cluster, the LocalEJBHome reference of the entity bean is stored in a HttpSession which allows it to failover to another server instance when a servicing server instance is unhealthy or unavailable.  Load Balancer and with at least two Application Server instances and two nodes of HADB  are required as minimum for configuration. The instruction for deployment and registering resources are for one application server instance, you should repeat the same for other instances.
 

Compiling and Assembling the Application



This section contains instructions to build and assemble the CMP Roster 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 from scratch, do the following:
    •  
    • Go to the ee-samples/roster/src directory

    •  
    • Execute the command $AS_HOME/bin/asant

    • The default target core will be executed to compile java files and rebuild the .jar and .ear files.
  1. Clean the application project area using the asant clean command. For example:
  2. $AS_HOME/bin/asant clean
Deploying the Sample Application

In this section, you will learn how to deploy the roster 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 Deployment

    Since a complete EAR file is supplied, the fastest means of setting up the application is to use the command line utilities described in this section.

    Deploying the pre-built RosterApp.ear file is simple. Deploy either Using the asant script or by Using the asadmin command.
     

    Using the asant script

    Please start your database server, if not started.

    If you choose to use the PointBase database, execute the following steps:
     

    1. Go to the src directory of the sample
    2. cd $AS_HOME/samples/ee-samples/roster/src

       
    3. Run asant using deploy task
    4. $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, execute the following steps:
     
    1. Go to the src directory of the sample

    2.  cd $AS_HOME/samples/ee-samples/roster/src
       
    3.  Run asant using deploy task
                  $AS_HOME/bin/asant deploy-ora

            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.

           Note that, it assumes the db host as localhost, db port as 1521 and sid as sun-appserv-samples.
           If you want to use different parameters, please use asant deploy-ora -Ddb.host=<db host>
            -Ddb.port=<db port> -Ddb.sid=<db sid>
     



    Using the asadmin command
       
    1. Go to the root of the sample directory
    2. cd $AS_HOME/samples/ee-samples/roster

       
    3. Execute asadmin to deploy application to the local application server instance. For example:
    4. $AS_HOME/bin/asadmin deploy -u <admin_username> -w <admin_password> -H <host> -p <adminserver_port> --type application --name RosterApp --instance <instance_name> RosterApp.ear
    Where <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).

    Now you need to register the resources to the Sun Java (tm) System application server. Proceed to Registering Resources.

    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

    Since a pre-built Enterprise Archive (EAR) 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.

       
    1. From your web browser, access the Sun Java (tm) System Application Server by entering the URL. For example:
    2. http://<server-host>:<admin-port>

       
    3. Enter the server administrator's username and password to access the admin server.

    4.  
    5. On the left panel, navigate the tree by clicking on the following:
    6. App Server Instances->server1->Applications->Enterprise Apps

       
    7. On the right panel, click on the Deploy button.
    8. Enter the File Path to select the file (from disk) to be deployed (RosterApp.ear)
      Click OK.

       
    9. Enter the application name if it's not already filled in
    10. Click OK


    If the deployment processes correctly, you will see the original panel displaying the RosterApp application as deployed.

    Now you need to register the resources to the Sun Java (tm) System application server. Proceed to Registering Resources.



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 deployment 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 server1

You should see output similar to what is displayed below:

RosterApp <application>
There are no standalone WAR modules

There are no standalone EJB modules
There are no connector modules




Undeploying the Sample Application

    To undeploy the application, do the following:

  • Go to the ee-samples/roster/src directory

  •  
  • Execute the command asant undeploy

  •  
  • Reconfigure the server instance.

  • $AS_HOME/bin/asadmin reconfig -u <admin_username> -w <admin_password> -H <host> -p <adminserver_port> <instance_name>


Registering Resources



Before run the sample application, you must first do the following:
  •  Please start your database server, if not started.

  •  
  •  Run the command asant setup  if you are going to use PointBase (that was bundled with the Platform Edition). To run the sample on Oracle please refer to Configuring Oracle database section below.

  •  
  •  OR do the following steps to create and register resources if you already have a connection to any database:
JDBC connection pool

asadmin create-jdbc-connection-pool --host <admin host> --port <admin port> --user <user> --password  <password> --instance <server instance name> --datasourceclassname <datasource classname> --property  User=<databaseusername>:Password=<databasepassword>:<url-property>="<database jdbc url>"   rosterPool

 In 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

asadmin create-jdbc-resource --host <admin host> --port <admin port> --user <user> --password <password>
--instance <server instance name> --connectionpoolid  rosterPool  jdbc/roster
 

Persistence Manager Factory resource

- JNDI name should be "jdo/roster" as the name is used in the deployment descriptor

asadmin create-persistence-resource --host <admin host> --port <admin port> --user <user> --password <password>  --instance <server instance name> --jdbcjndiname  jdbc/roster   --factoryclass
com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl  jdo/roster
 

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 tables from scratch using sql files (RosterApp.sql) in src/sql directory.

For more information on using PointBase, please refer to the Using PointBase with the Samples document.



Configuring Oracle database

To run sample with Oracle database, please follow the steps outlined below.  For more details see (How to run samples with Oracle database server) document.

  • For more information, please refer to General settings of the oracle document.
  • Create an RDBMS user
    1. cd <install_dir>/samples/ee-samples/roster/src/sql
    2. sqlplus to oracle as system user
    3. SQL> @createUser.sql
    4. exit sqlplus
       
  • Create RDBMS Tables
    1. cd <install_dir>/samples/ee-samples/roster/src/sql
    2. sqlplus to oracle as cmp user
    3. SQL> @RosterApp.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 roster 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.
     
Running the Sample Application

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.
  • On your browser go to the url : http://<host>:<port>/RosterClient
The following images are from running the sample.
 


Figure 1 - RosterApp
 
 


Figure 2  -  RosterApp: select different display option
 


Figure 3  -  RosterApp: List of League display option
 


Figure 4  -  RosterApp: Players of Sport display option
 


Figure 5  -  RosterApp: Invalidate the current HttpSession



Generating javadocs

To better understand sample application source code, you may refer to the related javadocs.

To generate javadocs, run the following command from .../ee-samples/roster/src:

        asant javadocs

After javadocs are generated, you may access them at samples/ee-samples/roster/javadocs/index.html.
 
 

Troubleshooting


  • 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.
Last Updated July 6, 2003