BEA Logo BEA WebLogic Enterprise Release 5.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   WebLogic Enterprise Doc Home   |   Samples & Related Topics   |   Previous Topic   |   Next Topic   |   Contents   |   Index

Stateless Session Bean Sample Application

 

This topic includes the following sections:

 


How the Stateless Session Bean Sample Works

This sample demonstrates the usage of stateless session EJBs using a simple stock trader application. This sample demonstrates how the client must maintain any persistent state -- such as the change in the cash account -- across repeated calls to the session EJB.

The EJB in this sample provides basic trading methods such as buying and selling stocks. Since there are no persistent stores involved in this sample, all the stock data are set in the deployment descriptor of the EJB as environment properties. The container supplies the data to the EJB through JNDI lookup operation.

The stateless session bean sample application implements the following classes:

Class

Description

Client

This bean:

  • Creates a trader and performs repeated buying and selling of shares.

  • Shows persistence of state between invocations to the TraderBean class.

  • Maintains state between invocations.

TraderBean

This bean does not manage any persistence of state between invocations on it.

TradeResult

This bean contains the results of a buy/sell transaction.

 


Building and Running the Stateless Session Bean Sample

To build and run the stateless session bean sample application, complete the following steps:

  1. Verify the environment variables.

  2. Create a work directory on your machine under the directory described in step 2 in the section Before you Build and Run the EJB Sample Applications.

  3. Change the protection attribute on the files for the stateless session bean sample application.

  4. Execute the runme command.

The following sections describe these steps, and also explain the following:

Verifying the Settings of the Environment Variables

Before building and running the sample application, you need to ensure that certain environment variables are set on your system. In most cases, these environment variables are set as part of the installation procedure. However, you need to check the environment variables to ensure they reflect correct information.

The following table lists the environment variables required to run the stateless session bean sample application.

Environment Variable

Description

TUXDIR

The directory path where you installed the WebLogic Enterprise software. For example:

Windows NT

TUXDIR=c:\wledir

UNIX

TUXDIR=/usr/local/wledir

JAVA_HOME

The directory path where you installed the JDK software. For example:

Windows NT

JAVA_HOME =c:\JDK1.2

UNIX

JAVA_HOME =/usr/local/JDK1.2

You may optionally set the following system environment variables to change their default value prior to running the stateless session bean sample application runme command. See the Administration Guide for more information about selecting appropriate values for these environment variables.

The following table lists the optional environment variables required to run the stateless session bean sample application.

Environment Variable

Description

HOST

The host name portion of the TCP/IP network address used by the ISL process to accept connections from Java clients. The default value is the name of the local machine.

PORT

The TCP port number at which the ISL process listens for incoming requests; it must be a number between 0 and 65535. The default value is 2468.

IPCKEY

The address of shared memory; it must be a number greater than 32769 unique to this application on this system. The default value is 55432.

Verifying the Environment Variables

To verify that the information for the environment variables defined during installation is correct, complete the following steps:

Windows NT

  1. From the Start menu, select Settings.

  2. From the Settings menu, select the Control Panel.

    The Control Panel appears.

  3. Click the System icon.

    The System Properties window appears.

  4. Click the Environment tab.

    The Environment page appears.

  5. Check the settings for TUXDIR and JAVA_HOME.

UNIX

  1. Enter the ksh command to use the Korn shell.

  2. Enter the printenv command to display the values of TUXDIR and JAVA_HOME, as in the following example:

    ksh prompt>printenv TUXDIR
    ksh prompt>printenv JAVA_HOME

Changing the Environment Variables

To change the environment variable settings, complete the following steps:

Windows NT

  1. From the Start menu, select Settings.

  2. From the Settings menu, select the Control Panel.

    The Control Panel appears.

  3. Click the System icon.

    The System Properties window appears.

  4. Click the Environment tab.

    The Environment page appears.

  5. On the Environment page in the System Properties window, click the environment variable you want to change or enter the name of the environment variable in the Variable field.

  6. Enter the correct information for the environment variable in the Value field.

  7. Click OK to save the changes.

UNIX

  1. Enter the ksh command to use the Korn shell.

  2. Enter the export command to set the correct values for the TUXDIR and JAVA_HOME environment variables, as in the following example:

    ksh prompt>export TUXDIR=directorypath
    ksh prompt>export JAVA_HOME=directorypath

Copying the Files for the Stateless Session Bean Sample Application into a Work Directory

You need to copy the files for the stateless session bean sample application into a work directory on your local machine. The following steps describe how to copy all the example files into a work directory.

  1. If you are using a UNIX system, enter the ksh command to use the Korn shell:

    prompt>ksh
    ksh prompt>

  2. Create a work directory on your machine under the directory described in step 2 in the section Before you Build and Run the EJB Sample Applications.

  3. Copy the contents of the following directory into the work directory:

    Windows NT

    %TUXDIR%\samples\j2ee\ejb\basic\statelessSession

    UNIX

    $TUXDIR/samples/j2ee/ejb/basic/statelessSession

The files copied into the work directory are in two categories:

Sample Application Files

Table 2-1 lists and describes all the files for this sample application.

Table 2-1 Sample Application Files

File

Description

ejb-jar.xml

The XML deployment descriptor file used to help add the bean to the EJB container.

weblogic-ejb-extensions.xml

A file containing the WebLogic Enterprise extensions to the deployment descriptor DTD.

Client.Java

The Java source code for the client.

TraderBean.java

The Java source code for the stateless session bean. This class contains the business logic method implementations and methods required by the Sun Microsystems, Inc. EJB 1.1 specification.

Trader.java

The Java source code for the Remote interface of the TraderBean class.

TraderHome.java

The Java source code for the Home interface of the TraderBean class.

TradeResult.java

Application-specific utility class used to carry a trade execution result between the EJB and the client.

ProcessingErrorException.java

Application-specific exception thrown by the TraderBean class for business methods.

index.html

File containing these instructions.

Utility Files

Table 2-2 lists and describes the utility files for this sample application. These files are generated based on the WebLogic Enterprise installation environment. The following files are generated in the same directory as where the source files are found.

Table 2-2 Utility Files

File

Description

runme.cmd

The Windows NT batch file that contains commands to set the environment, boot the server, and execute the client for this sample.

runme.ksh

The UNIX Korn shell script that contains commands to boot the server and execute the client for this sample.

run_client.cmd

The batch file to run the client on Windows NT systems.

run_client.ksh

The script file to run the client on UNIX systems.

setenv.cmd

The batch file to set the necessary environment variables on Windows NT systems.

setenv.ksh

The script file to set the necessary environment variables on UNIX systems.

ubbconfig

The WebLogic Enterprise server configuration file to be used on UNIX systems.

ubbconfig.nt

The WebLogic Enterprise server configuration file to be used on Windows NT systems.

ejb_basic_statelessSession.jar

The EJB JAR file that contains the source file classes, the container-specific class files generated by the ejbc command, and the deployment descriptor files. This is the EJB JAR file that is deployed on the WebLogic Enterprise server.

Changing the Protection Attribute on the Files for the Stateless Session Bean Sample Application

During the installation of the WebLogic Enterprise software, the sample application files are marked read-only. Before you can edit or build the files in the stateless session bean sample application, you need to change the protection attribute of the files you copied into your work directory, as follows:

Windows NT

prompt>attrib /S -r drive:\workdirectory\*.*

UNIX

prompt>ksh

ksh prompt>chmod +w /workdirectory/*.*

On the UNIX operating system platform, you also need to change the permission of runme.ksh and clean.ksh to give execute permission to those files, as follows:

ksh prompt>chmod +x *.ksh

Executing the runme Command

The runme command automates the following steps:

  1. Loads the UBBCONFIG file.

  2. Compiles the code for the stateless session bean sample application.

  3. Starts the server application using the tmboot command.

  4. Starts the client application.

  5. Stops the server application using the tmshutdown command.

To build and run the stateless session bean sample application, make sure you have copied the scripts described in Before you Build and Run the EJB Sample Applications, and enter the runme command, as follows:

Windows NT

prompt>cd workdirectory

prompt>runme basic statelessSession

UNIX

ksh prompt>cd workdirectory

ksh prompt>./runme.ksh basic statelessSession

A number of messages are displayed, along with whether or not the build procedure was successful. Note that the sample is not only built, but also the servers are booted and the client is run once.

Running the Sample Manually

After you have executed the runme command, you can run the sample manually if you like. To run the samples manually, complete the following steps:

  1. Change to the sample's work directory, if necessary.

  2. Make sure that your environment is set correctly by entering the following command:

    Windows NT

    prompt>setenv

    UNIX

    prompt>. ./setenv.ksh

  3. Boot the server and run the client by entering the following commands:

    Windows NT

    prompt>tmboot -y
    prompt>run_client.cmd

    UNIX

    prompt>tmboot -y
    prompt>./run_client.ksh

Processes and Files Generated by the Sample Application

When the you enter the tmboot command to start one of the EJB sample applications, the following server processes are started:

 


Stopping the Sample Application

You can stop the stateless session bean sample application by entering the following command:

prompt>tmshutdown -y

 


Stateless Session Bean Javadoc

The Javadoc for the stateless session bean example is in the following location:

Windows NT

%TUXDIR%/samples/j2ee/ejb/basic/statelessSession/index.html

UNIX

$TUXDIR\samples\j2ee\ejb\basic\statelessSession\index.html

If you are viewing this document in a browser, you can click the following link to display this Javadoc:

Package samples.j2ee.ejb.basic.statelessSession