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:

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 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:

  1. Build the example
  2. Configure the 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%\lib directory to your CLASSPATH, where %WL_HOME% refers to the WebLogic Server installation directory.

  4. 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:

    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.

Configure the WebLogic Server

  1. Start the WebLogic Server.
  2. Invoke the Administration Console in your browser.
  3. Click to expand the Services node in the left pane and expand the JMS node.
  4. Click to expand the Servers node.
  5. Click to expand the examplesJMSServer node.
  6. Right-click the Destinations node and choose Configure a new JMSQueue from the drop-down list.
  7. Enter exampleQueueReceive in the Name textfield.
  8. Enter weblogic.examples.jms.exampleQueueReceive in the JNDIName textfield.
  9. Click Create.
  10. Right-click the Destinations node and choose Configure a new JMSQueue from the drop-down list.
  11. Enter exampleQueueSend in the Name textfield.
  12. Enter weblogic.examples.jms.exampleQueueSend in the JNDIName textfield.
  13. Click Create.
  14. Click the Connection Factories node under the JMS node in the left pane.
  15. Click exampleQueue.
  16. Click the Targets tab in the right panel.
  17. Move examplesServer to the Chosen list box, if not already there.
  18. Click Apply.
  19. Click to expand the Deployments node in the left pane and select EJB. A list of deployed EJBs displays.
  20. Click the xml_messageformat deployment unit from the list.
  21. Click the Targets tab in the right-hand pane.
  22. Move examplesServer to the Chosen list box, if not already there.
  23. Click Apply.

Run the Example

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

  2. 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).

  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 the WebLogic server for the XML file that was sent to the JMS queue.

  4. 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:


Documentation is available at
http://e-docs.bea.com/wls/docs61

Copyright © 2001 BEA Systems, Inc. All Rights Reserved.