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:

 

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.

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 the Client code to see how the application works.

Building and Running this Example

The JMS examples included in the WebLogic Server 8.1 distribution are not shipped pre-built. To run these examples, first build them by following the instructions in this section.

The following section describes how to build and run the example:

  1. Build the Example
  2. Configure WebLogic Server
  3. Run the Example

Build the Example

  1. Build and deploy the TraderBean EJB from the stateful Session EJB example.

  2. Set up your development shell as described in Setting up your environment.

  3. 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.

  4. Build the example by executing the Java ant command. The Java ant command uses the build.xml file in the $SAMPLES_HOME\server\examples\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\examples\build\clientclasses\examples\jms\messageformat
    • EJBs: $SAMPLES_HOME\domains\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.

Configure 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.

  1. Start the examples WebLogic Server.
  2. Invoke the Administration Console in your browser.
  3. In the left pane, expand the Services -> JMS node.
  4. Expand the Connection Factories node. The preconfigured connection factory instances associated with the examplesServer are listed.
  5. Select the exampleQueue connection factory instance. A dialog displays in the right pane showing the tabs associated with this instance.
  6. Click the Target and Deploy tab.
  7. The WebLogic Server instances in the examples domain are listed in the Independent Servers box. If necessary, select the examplesServer check box.
  8. Click Apply to save the change.
  9. In the left pane, expand the Deployments node, and then select EJB Modules. A dialog displays in the right pane showing the tabs associated with the EJB modules.
  10. On the Configurtion tab, click the _appsdir_jms_messageformat_jar deployment unit.
  11. Click the Targets tab.
  12. The WebLogic Server instances in the examples domain are listed in the Independent Servers box. If necessary, select the examplesServer check box.
  13. Click Apply to save the change.

Run the Example

  1. Start the examples WebLogic Server in a new command shell.

  2. In your development shell, run the ClientSend client with the following command:
      prompt> java examples.jms.messageformat.ClientSend t3://hostname:port
    where:
    hostname
    refers to the machine on which WebLogic Server is running
    port
    refers to the port on which WebLogic Server is listening for connections

  3. 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.

  4. Run the ClientReceive client with the following command:
      prompt> java examples.jms.messageformat.ClientReceive t3://hostname:port

    You should see output similar to the following sample:

    START DOCUMENT
    
    ?xml version='1.0' encoding='UTF-8'?
    
        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

  Read more about: