WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

Package examples.xml.http

This example demonstrates passing XML documents between a client and servlet over HTTP.

See:
          Description

Class Summary
RequestHandler This class extends HandlerBase and is used to handle events created as an XML document is parsed by a SAX compliant parser.
StockClient This example works with SAXServlet included in this package to demonstrate how XML data is created, manipulated, and passed between a client and a servlet.
StockServlet This example shows how to pass XML data between a Java client and a servlet over HTTP.
 

Package examples.xml.http Description

This example demonstrates passing XML documents between a client and servlet over HTTP. This example uses the SAX API to parse the documents. The XML documents created in this example define requests for and results of operating upon an EJB.

The example illustrates:

In this example, StockServlet acts as a mediator between StockClient and TraderBean. StockClient accepts user input to define a stock trade transaction. This data is used to generate an XML document in the format defined by stocktrade.dtd (located in the samples/examples/xml/http directory of the WebLogic Server distribution) and the XML is sent to StockServlet via a POST. StockServlet creates an instance of RequestHandler and uses it to set the value of the org.xml.sax.HandlerBase attribute on the servlet request. This causes WebLogic Server to parse the incoming document using the SAX parser defined in the examples XML Registry. As the document is parsed, parsing events are passed to the RequestHandler which builds a Hashtable containing the documents information. This information is then used by the StockServlet to operate on TraderBean and execute the trade. StockServlet then receives the result of the trade from TraderBean, generates an XML document describing the results of the trade, and sends the XML back to StockClient via the HTTPServletResponse. StockClient parses the XML using a SAX parser and displays the results to the command shell.

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

  1. Build the example
  2. Configure the server
  3. Run the example

Build the Example

  1. This example uses the TraderBean from the StatefulSession EJB example. You must first build and deploy this EJB before running this example.

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

  3. Compile the example by executing the following commands or by executing the build script provided for this example in the samples/examples/xml/http directory. The script will perform the following steps:

    Note: You will receive deprecation messages when you build this example. This is because this example uses the JAXP API to obtain a parser. JAXP only supports the SAX 1.0 API, while the parser bundled with WebLogic Server supports the SAX 2.0 API. These deprecation messages can be ignored.

    1. Compile the client as shown in this example for Windows NT/2000:
        $ javac -d %CLIENT_CLASSES% StockClient.java

    2. Compile RequestHandler and StockServlet into the Examples Web App classes directory as shown in this example for Windows NT/2000:
        $ javac -d %EX_WEBAPP_CLASSES% StockServlet.java RequestHandler.java

Configure the Server

  1. Start the server with the examples configuration in a new command shell.
  2. Bring up the Administration Console in your browser.
  3. Click to expand the Services node in the left-hand pane.
  4. Click to expand the XML Registries node in the left-hand pane.
  5. Select the examplesXMLRegistry node.
  6. Select the Targets tab in the right-hand pane to display the Available and Chosen targets.
  7. Enable the examplesXMLRegistry on the examplesServer.
  8. The examplesXMLRegistry maps the stocktrade document type used in this example to the appropriate DTD file. You must now copy stocktrade.dtd located in the samples/examples/xml/http to the XML entity directory for the examplesXMLRegistry on the Admin Server. This directory is located at config/examples/xml/registries/examplesXMLRegistry in the WebLogic Server distribution of the Admin Server.

Run the Example

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

  2. In your development shell, run the StockClient client with the following command:
      $ java examples.xml.http.StockClient http://hostname:port/examplesWebApp/StockServlet
    where:
    hostname
    Host name of the WebLogic Server.
    port
    Port where the WebLogic Server is listening for connections (weblogic.system.ListenPort).

There's More...

Read more about:


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

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