Using BEA Jolt with BEA WebLogic Server

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Servlet with Enterprise JavaBean Example

To use the Servlet with Enterprise JavaBean example, see the following sections:

This Enterprise JavaBean (EJBean) example package contains the classes and other files necessary to set up and run an EJBean stateful session to a Tuxedo Server using Jolt. The package contents are as follows:


About the Servlet with JavaBean Example

This example demonstrates an Enterprise JavaBean (EJBean), and provides an example of a simple interface for accessing the Tuxedo Server. You can find the source code for this example in the /samples/jolt/wls/ejb/bankapp directory included in the BEA Tuxedo distribution.

Running this example before attempting to create your own EJBeans 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 as follows:

The client browser 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 performs a series of transactions for the Teller that has just been created:
    • Gets the current balance for account 10000.
    • Performs Transaction 1: Deposits $100 into the account, and displays the balance.
    • Performs Transaction 2: Deposits $200 (more than the transaction limit of $300).
    • Note: In Transaction 1, a single call is made, and is automatically committed. In Transaction 2, a begin() and commit() bracket two separate requests (a deposit and a withdrawal).
    • Attempts to withdraw $100 more than the balance of the account.
    • Catches an ApplicationException, retrieves the status messages embedded in the exception, and rolls back Transaction 2.
    • Gets the final balance for the account.
    • Removes the teller.
    • You can see in Transaction 2 how the balance is successfully rolled back to what it was at the end of Transaction 1.


Preparing to Use the Servlet with JavaBean 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 and which classes are used for the different objects and interfaces, and then look at to see how the application works.

The following sections provide details for using this example:

Set Up Your Environment

You need to add a Jolt connection pool that connects to the public Tuxedo Server at BEA, as described in "Step 3. Configure the Servlet in WebLogic Server," in Appendix B, Simple Servlet Example. When you're finished, the config.xml configuration file will contain the following sections:

Name="MyStartup Class"
Name="MyJolt Connection Pool"

Build the Example

After configuring your WebLogic Server development environment, you need to build the example. BEA Jolt provides separate build scripts for Windows 2003 and UNIX, as follows:

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

$ build

To build under Microsoft's JDK for Java, use:

$ build -ms

The scripts will build the example and place the files in the following default WebLogic Server directories on a Windows 2003 system:


Run the Servlet with JavaBean Example

When WebLogic Server is started in the default \config\mydomain directory, the EJBean example is automatically deployed in the \applications directory.

  1. Start the WebLogic Server in the \config\mydomain directory. 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 Deployments. You should see ejb.jolt.bankapp deployed and should be able to monitor its activity.
  2. Open a separate command-line window, and then run the client by entering the following command:
  3. $ java examples.jolt.ejb.bankapp.Client

    If you are not running the WebLogic Server with its default settings, you will have to use the following command line:

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

    where the following parameters are defined as follows:

    • WebLogicURL—the domain address of the WebLogic Server
    • Port—the port listening for connections (weblogic.system.ListenPort)
    • The following optional parameters are interpreted by the client in the order in which they are listed:

    • url—unique resource location of Server, such as t3://localhost:7001
    • user—username, default null
    • password—user password, default null
  4. If you are running the Client example, you should get output that is similar to the following from the client application:
  5. 4.	Beginning jolt.bankapp.Client...
    6. Created teller Terry
    8. Getting current balance of Account 10000 for Erin
    9. Balance: 27924.02
    11. Start Transaction 1 for Erin
    13. Depositing 100.0 for Erin
    14. Balance: 28024.02
    16. End Transaction 1 for Erin
    18. Start Transaction 2 for Erin
    20. Depositing 200.0 for Erin
    21. Balance: 28224.02
    23. Withdrawing 28324.02 for Erin
    24. Transaction error:
    25. examples.jolt.ejb.bankapp.TransactionErrorException: Teller error: application
    26. exception:
    27. Account Overdraft
    29. Rolling back transaction for Erin
    31. End Transaction 2 for Erin
    33. Getting final balance of Account 10000 for Erin
    34. Balance: 28024.02
    36. Removing teller Terry
    End jolt.bankapp.Client...
    Note: Note how the final balance shows that Transaction 2 was rolled back to the balance at the end of Transaction 1.

You can read more about EJBs in the Programming WebLogic Enterprise JavaBeans guide. To learn more about using BEA Jolt, refer to the Using BEA Jolt guide.

  Back to Top       Previous  Next