Sun ONE logo     
Stateless Simple EJB Converter Sample Application



Stateless Simple EJB Converter Sample Application


This document describes how to utilize the Stateless Simple EJB Converter sample application in conjunction with Sun Java (tm) System Application Server 7.

This sample application document contains the following sections:



Overview

The Converter sample is a simple application based on one EJB component, a single JSP and a client. Assembling this application and deploying it to Sun Java (tm) System Application Server provides an introduction to the server's assembly, deployment and registration tools.

For the sake of instruction, let's assume that you want to create a small application to demonstrate web-based access to a stateless session bean via a JSP. The application look and feel is described as follows:

  1. Bring up a web page with a form like the one displayes in Figure 1.



Figure 1    Main page

  1. Enter a numeric figure and press the Submit button.

    • Since the page is a JSP, it invokes the ConverterBean with a request to convert 100 units of USD to Yen and 100 Yen to Euro.

    • The stateless session bean returns the results to the caller and the JSP displays the result in the same page.

    • As a result of the JSP execution, you see the page displayed in Figure 2 returned to your browser



Figure 2    Result page

The following instructions describe how to manually deploy the application. You may want to experiment by modifying and redeploying the Simple Web Sample example.



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:

    Execute asant under <install_dir>/samples/ejb/stateless/converter/src

    The default target core will be executed to rebuild the .jar and .ear files.

  2. Deploy the application.

    Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.

  3. 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 stateless-converter.ear file is supplied with the application server installation. The pre-built stateless-converter.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.

  • UNIX

    Execute <install_dir>/domains/domain1/admin-server/bin/startserv

  • Windows

    Start->Programs->Sun Java (tm) System Application Server 7->Start Application Server

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 Deployment Tool 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.


Using the asant script

  1. Go to the src directory of the sample. For example:

    cd <install_dir>/samples/ejb/stateless/converter/src

  2. Run asant using deploy task. For example:

    %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 ONE application server.


Using the asadmin command

  1. Go to the root of the sample directory. For example:

    cd <install_dir>/samples/ejb/stateless/converter

  2. Execute asadmin to deploy application to the local application server instance. For example:

    asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> stateless-converter.ear

The deployment process involves the following operations:

  • 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:

    • Parses the EAR file and embedded JAR and WAR files

    • Explodes the bits into repository

    • Registers the J2EE application "stateless-converter" by updating server.xml

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. Navigate as follows:

    Application Server Instances --> <server instance> --> Applications --> Enterprise Applications

  3. Click Deploy.

  4. Click Browse to locate the stateless-converter.ear file.

    The ear file is located under <install_dir>/samples/ejb/stateless/converter.

  5. Click OK.

  6. Enter stateless-converter in the Application Name field.

  7. Click OK.

  8. Click the stateless-converter link to verify that the application is deployed.


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:

    asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>

  2. Alternately, you may navigate the Admin tool GUI to the following:

    App Server Instances>server1>Applications.

  3. 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/ejb/stateless/converter/javadocs/index.html



Running the Sample Application



To run the application, type-in the following URL: http://<hostname>:<port>/converter

The sample will convert your input from dollar to yen and from yen to euro.


Running the Sample using the client interface

Running the sample using client interface is a two step process:

  1. Go to the directory where the sample has been deployed. For example:

    cd <install_dir>/domains/domain1/server1/applications/j2ee-apps/stateless-converter_1/

  2. Run appclient using the following instructions:

    appclient -client stateless-converterClient.jar -name ConverterClient -textauth

    You will see the following output:

    ...

    12160.00

    0.77

    ...



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 "stateless-converter", 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/domain1/<server-instance>/logs/server.log to learn what went wrong.



Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated August 21, 2002