All Examples  All Jolt Examples  This Package

Package examples.jolt.ejb.bankapp

Enterprise JavaBean stateful session to TUXEDO Server using Jolt
example package and classes

about this example

This example is a package that demonstrates an Enterprise JavaBean. Please run this example before attempting to create your own Enterprise JavaBeans, as it will show you the different steps involved. The example is a stateful session EJBean called TellerBean that contacts a TUXEDO Server using Jolt for WebLogic and conducts transactions.

The example demonstrates:

The Client application performs these steps:
  1. Contacts the Teller home ("TellerHome") through JNDI to find the EJBean
  2. Creates a Teller ("Terry")
  3. The application then:
    1. Gets the current balance for account 10000
    2. Transaction 1: Deposits 100 into the account, and displays the balance
    3. Transaction 2: Deposits 200 (more than the transaction limit of 300)
    4. Attempts to withdraw 100 more than the balance of the account
    5. Catches an ApplicationException, retreives the status messages embedded in the exception and rolls back Transaction 2
    6. Gets the final balance for the account
  4. Removes the Teller
You can see in the Transaction 2 how the balance is successfully rolled back to what it was at the end of Transaction 1.

Note that in Transaction 1, a single call is made, and is automatically committed. In Transaction 2, a begin() and commit() bracket two seperate requests (a deposit and a withdrawl).

The bean provides an example of a simple interface for accessing the TUXEDO Server.

how to use this example

To get the most out of this example, first read through the source code files to see what is happening. Start with DeploymentDescriptor.txt to find the general structure of the EJBean, which classes are used for the different objects and interfaces, then look at Client.java to see how the application works.

In general, you'll need to adjust certain properties to match your setup. You'll need to edit the entry for the property that begins with "weblogic.ejb.deploy" in the weblogic.properties file to deploy the EJBean. The property is commented out in the default properties file; make sure that you uncomment out all the lines of the property.

These three sections cover what to do:

  1. Build the example
  2. Set your environment
  3. Run the example

Build the example

Set up your development environment as described in Setting your development environment.

We provide separate build scripts (in the directory above this one: /examples/jolt/ejb) for Windows NT and UNIX:

The "build" scripts builds individual examples, such as this entry for Windows:

$ build
To build under Microsoft's JDK for Java, use
$ build -ms
These scripts will build the example and place the files in the correct locations:

Set your environment

Deploy the EJBean by adding the path to the .jar file to the "weblogic.ejb.deploy" property.

We provide a commented-out version in the property that begins with "weblogic.ejb.deploy" that you can use. You'll need to adjust the property depending on which EJBeans you're building and are deploying, or if the location of the files differs from the installed location.

Note: If you're running under the Microsoft SDK for Java, you'll also need to add the path to the .jar to the CLASSPATH for your WebLogic Server.

You'll need to add a Jolt connection pool that connects to the public TUXEDO Server at BEA by adding to your weblogic.properties file:

# Demo Jolt pool
  weblogic.system.startupClass.demojoltpoolStart=\
    bea.jolt.pool.servlet.weblogic.PoolManagerStartUp

  weblogic.system.startupArgs.demojoltpoolStart=\
    poolname=demojoltpool,\
    appaddrlist=//beademo1.beasys.com:8000,\
    failoverlist=//beademo1.beasys.com:8000,\
    minpoolsize=1,\
    maxpoolsize=3

  weblogic.system.shutdownClass.demojoltpoolStop=\
    bea.jolt.pool.servlet.weblogic.PoolManagerShutDown
  weblogic.system.shutdownArgs.demojoltpoolStop=\
    poolname=demojoltpool

Run the example

  1. Start the WebLogic Server. You can check that the EJBean has been deployed correctly either by checking the server command line window, or by opening the Console and examining "EJB" under the "Distributed objects"; you should see bankapp.TellerHome deployed, and can monitor its activity.

  2. Run the client in a separate command line window. Set up your client as described in Setting your development environment, and then run the client by entering:
    $ java examples.jolt.ejb.bankapp.Client

    If you're not running the WebLogic Server with its default settings, you will have to run the client using:

    $ java examples.jolt.ejb.bankapp.Client "t3://WebLogicURL:Port"

    where:

    WebLogicURL
    Domain address of the WebLogic Server
    Port
    Port that is listening for connections (weblogic.system.ListenPort)

    Parameters are optional, but if any are supplied, they are interpreted in this order:

    Parameters:
    url - URL such as "t3://localhost:7001" of Server
    user - User name, default null
    password - User password, default null

  3. If you're running the Client example, you should get output similar to this from the client application:
    Beginning jolt.bankapp.Client...
    
    Created teller Terry
    
    Getting current balance of Account 10000 for Erin
    Balance: 27924.02
    
    Start Transaction 1 for Erin
    
      Depositing 100.0 for Erin
      Balance: 28024.02
    
    End Transaction 1 for Erin
    
    Start Transaction 2 for Erin
    
      Depositing 200.0 for Erin
      Balance: 28224.02
    
      Withdrawing 28324.02 for Erin
      Transaction error:
      examples.jolt.ejb.bankapp.TransactionErrorException: Teller error: application
     exception:
    Account Overdraft
    
      Rolling back transaction for Erin
    
    End Transaction 2 for Erin
    
    Getting final balance of Account 10000 for Erin
    Balance: 28024.02
    
    Removing teller Terry
    
    End jolt.bankapp.Client...
    Note how the final balance shows that Transaction 2 was rolled back to the balance at the end of Transaction 1.

there's more

Read more about EJB in the Developers Guide, Using WebLogic Enterprise JavaBeans.

Read more about Jolt in the Developers Guide, Using Jolt for WebLogic.

Copyright © 1998-1999 BEA Systems, Inc. All rights reserved.

Last updated 09/26/1999