![]() |
Stateless Checker EJB Sample Application |
Stateless Checker EJB Sample Application
This document describes how to utilize the Stateless Checker EJB sample application in conjunction with Sun ONE Application Server version 7.This sample application document contains the following sections:
Overview
Compiling and Assembling the Sample Application
Deploying the Sample Application
Overview
This simple stateless bean demonstrates the use of environment entries or configurable parameters. It uses two environment entries as defined in the deployment descriptor (ejb-jar.xml) of the bean. They are:Stored in an enterprise bean's deployment descriptor, an environment entry is a name-value pair that allows you to customize the bean's usiness logic without changing its source code. This bean calculates discounts, based on two environment entries named Discount Percent and Discount Level.
The business method in the bean applyDiscount looks up these environment entries, makes a calculation and returns the discounted amount.
When you try to run the client using appclient, it will look as follows:
> appclient -client stateless-checkerClient.jar -name CheckerClient -textauth
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 the J2EE Application. For example:
Deploy the application.
- Execute asant under <install_dir>/samples/ejb/stateless/checker/src
- The default target core will be executed to rebuild the .jar and .ear files.
Clean the web application project area. For example:
- Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.
- Execute asant clean
- This will remove the sample application assemble and build directories.
Deploying the Sample Application
A pre-built stateless-checker.ear file is supplied with the application server installation. The pre-built stateless-checker.ear file is an Enterprise Archive (.ear) file that contains, the EJB .jar file and the web applicatation .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
Select one of the following approaches to deploying the application:
Windows
- Execute <install_dir>/domains/domain1/admin-server/bin/startserv
- Start->Programs->Sun ONE Application Server 7->Start Application Server
Command Line-based Deployment describes how to manually register the application in Sun ONE 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 ONE 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.
Go to the src directory of the sample. For example:
Run asant using deploy task. For example:
- cd <install_dir>/samples/ejb/stateless/checker/src
- %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.
Go to the root of the sample directory. For example:
The deployment process involves the following operations:
Execute asadmin to deploy application to the local application server instance. For example:
- cd <install_dir>/samples/ejb/stateless/checker
- asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> stateless-checker.ear
Authenticates against the local application server's administrative server
If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.The EAR file is transferred to the administrative server
The administrative server begins the registration process:
GUI-based Deployment
To deploy the EAR file, follow these steps:
Log in to the web-based administration tool from the browser.
Click Deploy.
- Application Server Instances --> <server instance> --> Applications --> Enterprise Applications
Click Browse to locate the stateless-checker.ear file.
Click OK.
- The ear file is located under <install_dir>/samples/ejb/stateless/checker.
Enter stateless-checker in the Application Name field.
Click the stateless-checker link to verify that the application is deployed.
Verifying Deployment
As an optional step, you can use the Sun ONE 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:
Execute the command asadmin list-components to look at applications deployed with a server instance. For example:
Alternately, you may navigate the Admin tool GUI to the following:
- asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>
On the left frame, Click on Enterprise Apps to display list of applications deployed on server.
- App Server Instances>server1>Applications.
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/stateless/checker/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:
Run appclient using the following instructions:
- cd <install_dir>/domains/domain1/server1/applications/j2ee-apps/stateless-checker_1/
- appclient -client stateless-checkerClient.jar -name CheckerClient -textauth
- You will see the following output:
- ...
- discount = 5700.0
- ...
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-checker", 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