|
|
| WebLogic Server 7.0 Code Examples, BEA Systems, Inc. |
Package examples.jms.messageformat
This example demonstrates how to use Message-driven beans to implement a
simple stock-trading scenario in which the stock data is sent as an XML
document.
See:
Description
|
Class Summary |
| ClientReceive |
This class shows how to establish a connection to and receive messages from
a JMS queue. |
| ClientSend |
This class asks the user to input data to define a stock trade transaction. |
| MessageTraderBean |
This class reads the XML data from a JMS queue, parses it and and
calls the statefulSession.TraderBean EJB to actually
perform the stock trade transaction. |
| RequestHandler |
This class extends HandlerBase and is used to handle events
created as an XML document is parsed by a SAX compliant
parser. |
Package examples.jms.messageformat Description
This example demonstrates how to use Message-driven beans to implement a
simple stock-trading scenario in which the stock data is sent as an XML
document.
The example illustrates how to:
- generate stock trade data as an XML file and send it to a JMS queue to
await further processing.
- use a Message-driven bean to first parse the XML file using a SAX parser
and then operate on TraderBean (a stateful Session EJB created in
the EJB examples) to execute the stock trade.
- pass the resulting stock trade information in form of XML data to a
different JMS queue.
- have a Client receive the data from the second JMS queue, parse it with
a SAX parser, and print the final result of the trade.
Overview of the Example
To get the most out of this example, first read through the source
code files.
- Client applications
- ClientSend.java - client application that sends XML data to a JMS queue.
- ClientReceive.java - client application that receives XML data from a JMS queue.
- XML parsing event handler
- RequestHandler.java - class that handles the events created as the XML document is parsed in the MessageTraderBean Message-driven EJB.
- Deployment
- ejb-jar.xml - describes the MessageTraderBean Message-driven EJB.
- weblogic-ejb-jar.xml - describes how to deploy the MessageTraderBean Message-driven EJB.
- Message-Driven Bean
- MessageTraderBean.java
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 code to see how the application works.
Building and Running this Example
The JMS examples included in the WebLogic Server 7.0 distribution are not
shipped pre-built. To run these examples, you must first build them by
following the instructions in this section.
The following section describes how to build and run the example:
- Build the example
- Configure WebLogic Server
- Run the example
- Build and deploy the TraderBean EJB from the stateful Session EJB example.
- Set up your development shell as described in
Setting up your environment.
- Add the xmlx.jar file located in the
WL_HOME\server\lib
directory to your CLASSPATH,
where WL_HOME refers
to the WebLogic Server installation directory.
- Build the example by executing the Java ant command.
The Java ant command uses the
build.xml file in the SAMPLES_HOME\server\src\examples\jms\messageformat
directory, where SAMPLES_HOME refers to the
directory for all samples and examples for the WebLogic Platform.
prompt> ant
The Java ant command builds the example and copies the files to the following directories:
- Client files: SAMPLES_HOME\server\stage\examples\clientclasses\examples\jms\messageformat
- EJBs: SAMPLES_HOME\server\config\examples\applications\jms_messageformat.jar
WebLogic Server automatically deploys the EJB as soon as the build command
copies the EJB files to the correct directory. If WebLogic Server is not
running, the EJB is deployed as soon as you start WebLogic Server.
The JMS exampleQueueSend and exampleQueueReceive destinations for
the ClientSend and ClientReceive applications do not have to be
configured as they are already included in the build.xml file.
- Start WebLogic Server.
- Invoke the Administration Console in
your browser.
- Click to expand the JMS node in the left pane.
- Click the Connection Factories node under the JMS node in the left pane. A list of
connection factories displays.
- Click the exampleQueue connection factory.
- Click the Targets tab in the right panel.
- On the Servers tab, move examplesServer to the Chosen column, if it's not
already there.
- Click Apply.
- In the left pane, click to expand the Deployments node, and then select EJB. A list of deployed
EJBs displays.
- Click the _appsdir_jms_messageformat_jar deployment unit from the list.
- Click the Targets tab in the right pane.
- Move examplesServer to the Chosen column, if it's not already there.
- Click Apply.
Run the Example
- Start WebLogic Server in a new command shell.
- In your development shell, run the ClientSend client with the following command:
prompt> java examples.jms.messageformat.ClientSend t3://hostname:port
where:
- hostname
- Host name of WebLogic Server.
- port
- Port where WebLogic Server is listening for connections.
- Enter whether you want to buy or sell shares of BEAS or MSFT.
You should see output similar to the following sample:
Action ("Buy" or "Sell", "quit" to quit): buy
Symbol ("BEAS" or "MSFT", "quit" to quit): BEAS
Number of shares ("quit" to quit): 56
Sending trade information...
Your message has been sent to queue
Check the shell from which you started WebLogic Server for the XML file
that was sent to the JMS queue.
- Run the ClientRecieve with the following command:
prompt> java examples.jms.messageformat.ClientReceive t3://hostname:port
You should see output similar to the following sample:
START DOCUMENT
ELEMENT: traderesult
ATTR: action = bought
ATTR: symbol = BEAS
ATTR: numShares = 56
ATTR: price = 100.0
ATTR: changeInAccount = -5600.0
END_ELM: traderesult
END DOCUMENT
There is no message in the queue: weblogic.examples.jms.exampleQueueReceive
There's More...
Read more about:
Copyright © 2002 BEA Systems, Inc. All Rights Reserved.