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:

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

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

    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 WebLogic Server.
  2. Invoke the Administration Console in your browser.
  3. Click to expand the JMS node in the left pane.
  4. Click the Connection Factories node under the JMS node in the left pane. A list of connection factories displays.
  5. Click the exampleQueue connection factory.
  6. Click the Targets tab in the right panel.
  7. On the Servers tab, move examplesServer to the Chosen column, if it's not already there.
  8. Click Apply.
  9. In the left pane, click to expand the Deployments node, and then select EJB. A list of deployed EJBs displays.
  10. Click the _appsdir_jms_messageformat_jar deployment unit from the list.
  11. Click the Targets tab in the right pane.
  12. Move examplesServer to the Chosen column, if it's not already there.
  13. Click Apply.

Run the Example

  1. Start 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
    Host name of WebLogic Server.
    port
    Port where 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 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:


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

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