|
|
| WebLogic Server 6.1 Code Examples, BEA Systems, Inc. |
Package examples.xml.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.xml.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 MessageTraderBean Message-driven EJB,
then look at the ClientSend and the
ClientReceive code to see how the application works.
Building and Running this Example
The XML examples included in the WebLogic Server 6.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 the 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%\lib
directory to your CLASSPATH,
where %WL_HOME% refers
to the WebLogic Server installation directory.
- Compile the example by executing the Java ant command.
The Java ant command uses the
build.xml file, located in the samples/examples/xml/messageformat
directory, to build the example.
The Java ant command builds the example and copies the files to the following directories
of the WebLogic Server:
- Client files: to /config/examples/clientclasses
- EJBs: to /config/examples/applications/xml_messageformat.jar
The WebLogic server automatically deploys the EJB as soon as the build command
copies the EJB files to the correct directory. If the WebLogic server is not
running, the EJB is deployed as soon as you start the WebLogic server.
- Start the WebLogic Server.
-
Invoke the Administration Console in your browser.
- Click to expand the Services node in the left pane and expand the
JMS node.
- Click to expand the Servers node.
- Click to expand the examplesJMSServer node.
- Right-click the Destinations node and choose Configure a new JMSQueue from the drop-down list.
- Enter exampleQueueReceive in the Name textfield.
- Enter weblogic.examples.jms.exampleQueueReceive in the JNDIName textfield.
- Click Create.
- Right-click the Destinations node and choose Configure a new JMSQueue from the drop-down list.
- Enter exampleQueueSend in the Name textfield.
- Enter weblogic.examples.jms.exampleQueueSend in the JNDIName textfield.
- Click Create.
- Click the Connection Factories node under the JMS node in the left pane.
- Click exampleQueue.
- Click the Targets tab in the right panel.
- Move examplesServer to the Chosen list box, if not already there.
- Click Apply.
- Click to expand the Deployments node in the left pane and select EJB. A list of deployed EJBs displays.
- Click the xml_messageformat deployment unit from the list.
- Click the Targets tab in the right-hand pane.
- Move examplesServer to the Chosen list box, if not already there.
- Click Apply.
Run the Example
- Start the WebLogic Server in a new command shell.
- In your development shell, run the ClientSend client with the following command:
$ java examples.xml.messageformat.ClientSend t3://hostname:port
where:
- hostname
- Host name of the WebLogic Server.
- port
- Port where the WebLogic Server is listening for connections
(weblogic.system.ListenPort).
- 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 the WebLogic server for the XML file
that was sent to the JMS queue.
- Run the ClientRecieve with the following command:
$ java examples.xml.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
setSessionContext called
ejbCreate called
buy (Erin, BEAS, 56)
ejbRemove called
There is no message in the queue: weblogic.examples.jms.exampleQueueReceive
There's More...
Read more about:
Copyright © 2001 BEA Systems, Inc. All Rights Reserved.