Table of Contents Previous Next PDF


Servlet with Enterprise JavaBean Example

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:
Teller (remote interface documentation and source)
TellerHome (home interface documentation and source)
TellerResult (application-specific utility documentation and source)
ProcessingErrorException (application-specific exception documentation and source)
TransactionErrorException (application-specific exception documentation and source)
TellerBean (EJBean documentation and source)
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 Oracle 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.
2.
3.
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).
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 Client.java 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 Oracle, 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:
<StartupClass
ClassName="bea.jolt.pool.servlet.weblogic.PoolManagerStartUp"
FailureIsFatal="false"
Name="MyStartup Class"
Targets="myserver"
/>
<JoltConnectionPool
ApplicationPassword="tuxedo"
MaximumPoolSize="5"
MinimumPoolSize="3"
Name="MyJolt Connection Pool"
PrimaryAddresses="//TUXSERVER:6309"
RecvTimeout="300"
SecurityContextEnabled="true"
Targets="myserver"
UserName="joltuser"
UserPassword="jolttest"
UserRole="clt"
/>|
<ShutdownClass
ClassName=”bea.jolt.pool.servlet.weblogic.PoolManager
ShutDown.”
/>
Build the Example
After configuring your WebLogic Server development environment, you need to build the example. Oracle Jolt provides separate build scripts for Windows 2003 and UNIX, as follows:
Windows 2003: %TUXDIR%\samples\jolt\wls\ejb\ bankapp\build.cmd
UNIX: $TUXDIR/samples/jolt/wls/ejb/bankapp/build.sh
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:
Client files in: d:\bea\wlserver6.1\config\examples
EJBean in: d:\bea\wlserver6.1\config\mydomain\applications
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.
$ 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:
The following optional parameters are interpreted by the client in the order in which they are listed:
3.
If you are running the Client example, you should get output that is similar to the following from the client application:
4. Beginning jolt.bankapp.Client...
5.
6. Created teller Terry
7.
8. Getting current balance of Account 10000 for Erin
9. Balance: 27924.02
10.
11. Start Transaction 1 for Erin
12.
13. Depositing 100.0 for Erin
14. Balance: 28024.02
15.
16. End Transaction 1 for Erin
17.
18. Start Transaction 2 for Erin
19.
20. Depositing 200.0 for Erin
21. Balance: 28224.02
22.
23. Withdrawing 28324.02 for Erin
24. Transaction error:
25. examples.jolt.ejb.bankapp.TransactionErrorException: Teller error: application
26. exception:
27. Account Overdraft
28.
29. Rolling back transaction for Erin
30.
31. End Transaction 2 for Erin
32.
33. Getting final balance of Account 10000 for Erin
34. Balance: 28024.02
35.
36. Removing teller Terry
37.
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 Oracle Jolt, refer to the Using Oracle Jolt guide.

Copyright © 1994, 2017, Oracle and/or its affiliates. All rights reserved.