|
| 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:
- Explicitly writing XML documents to an output stream
- Validating and parsing XML data using a SAX validating parser
- Passing XML data between a client and servlet via an HTTP POST
- Operating upon an EJB based on data receive via XML
- Publishing DTDs over HTTP for external entity resolution
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:
- Build the example
- Configure the server
- Run the example
- This example uses the TraderBean
from the StatefulSession
EJB example. You must first build and deploy this EJB before running
this example.
- Set up your development shell, as described in
Setting up your environment.
- 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.
- Compile the client as shown in this example for Windows NT/2000:
$ javac -d %CLIENT_CLASSES% StockClient.java
-
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
- Start the server with the examples
configuration in a new command shell.
- Bring up the Administration Console in your browser.
- Click to expand the Services node in the left-hand pane.
- Click to expand the XML Registries node in the left-hand pane.
- Select the examplesXMLRegistry node.
- Select the Targets tab in the right-hand pane to display the Available and Chosen targets.
- Enable the examplesXMLRegistry on the examplesServer.
- 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
-
Start the WebLogic Server in a new command shell.
-
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:
Copyright © 2000 BEA Systems, Inc. All Rights Reserved.