|
|
| WebLogic Server 7.0 Code Examples, BEA Systems, Inc. |
Package examples.ejb11.basic.statelessSession
This example is a package that demonstrates an
Enterprise JavaBean.
See:
Description
|
Interface Summary |
| Trader |
The methods in this interface are the public face of TraderBean. |
| TraderHome |
This interface is the home interface for the TraderBean.java,
which in WebLogic is implemented by the code-generated container
class TraderBeanC. |
|
Class Summary |
| Client |
This class illustrates calling a stateless Session Bean and performing
the following exercises:
Create a Trader
Buy some shares using the Trader
Sell some shares using the Trader
Remove the Trader
|
| TraderBean |
TraderBean is a stateless Session Bean. |
| TradeResult |
This class reflects the results of a buy/sell transaction. |
Package examples.ejb11.basic.statelessSession Description
This example is a package that demonstrates an
Enterprise JavaBean. The example is a stateless session EJBean
called TraderBean.
The example demonstrates:
- Usage of a session EJBean
- Stateless; client must maintain any state across calls to the EJBean
- Using application-defined exceptions and utilities
- Client Application
Client Application
The
Client
application performs these steps:
- Creates a Trader
- Buys and sells shares of "BEAS", "MSFT", "AMZN", and "HWP"
(The EJB does not actually "buy" or "sell"; it
simulates the actions of accessing a database.)
- Removes the Trader
The application demonstrates how the client must maintain any
persistent state -- such as the change in the cash account -- across
repeated calls to the session EJBean.
All the logic for the balance is encapsulated
in the Client, unlike the
stateful session example,
where all the persistence is provided by the container and the
logic is maintained in the EJBean.
To get the most out of this example, first read through the source code files
to see what is happening.
Start with the XML deployment files ejb-jar.xml and weblogic-ejb-jar.xml 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.
Pre-Built Examples
This EJB 1.1 example is not shipped pre-built. Before you can run this example, you must first build it following the instructions in Build the example.
These three sections cover what to do:
- Build the example
- Configure the server
- Run the example
Set up your development shell as described in
Setting up your environment.
We provide a build script for you to build the example:
The build script is build.xml.
Run the build script using the following Java ant command:
prompt> ant
The script will build the example and place the files in the
correct locations in your WebLogic Server distribution:
- Client.jar file: in SAMPLES_HOME\server\stage\examples\clientclasses
- EJB (in EAR file): in SAMPLES_HOME\server\config\examples\applications\ejb11_basic_statelessSession.ear
Running the build script places the EJB in the %applications% directory, where it automatically
deploys once the server is started. If you are already running the server and then build
the EJB, it is automatically placed in this directory and instantly deployed.
Additional information on using the build scripts
is found in Building Enterprise JavaBean examples
- Start the WebLogic Server.
-
Start the Administration Console.
- Click to expand the Deployments node in the left pane and select EJB.
A list of deployed EJBs displays in the left pane.
- Choose the EJB that you want to deploy from the list of deployment units.
- On the Edit EJB Descriptor page in the right pane, select the Targets tab.
- Verify that the EJB is deployed on the examplesServer. The examplesServer should be listed in the Chosen column.
Run the example
- Run the client in a separate command line window. Set up your client as described in
Setting up your environment,
and then run the client by entering:
prompt> ant run
- If you're running the Client example,
you should get output similar to this from the client application:
Beginning statelessSession.Client...
Creating a trader
Buying 100 shares of BEAS.
Buying 200 shares of MSFT.
Buying 300 shares of AMZN.
Buying 400 shares of HWP.
Selling 100 shares of BEAS.
Selling 200 shares of MSFT.
Selling 300 shares of AMZN.
Selling 400 shares of HWP.
Removing the trader
End statelessSession.Client...
There's more...
Read more about EJB in
BEA
WebLogic Server Enterprise Java Beans.
Copyright © 2002 BEA Systems, Inc. All Rights Reserved.