All Examples XML Examples
package examples.xml.http
XML-HTTP example package and classes
about this example
This 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 EJBean 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 XML in the format defined by
stocktrade.dtd and the
XML is sent to StockServlet
via a POST. StockServlet creates
an instance of RequestHandler to
parse the XML using a validating SAX parser and operates on
TraderBean to execute the trade.
StockServlet then receives the result
of the trade from TraderBean, generates
XML in the format of traderesult.dtd, and
sends the XML back to StockClient via
the HTTPServletResponse.
StockClient parses the XML
using a validating SAX parser and displays the results to the console.
The DTDs used to validate the XML documents are made accessible to the client
and servlet over HTTP by copying the DTDs to the document root.
how to use this example
Build the example:
- This examples uses the TraderBean
from the StatefulSession
EJB example. You must first build and deploy this EJBean before running
this example.
- Set up your development shell, as described in
Setting up
your environment.
-
Compile the client as shown in this example for Windows NT:
$ javac -d %CLIENT_CLASSES% StockClient.java
-
Compile RequestHandler
as shown in this example for Windows NT:
$ javac -d %SERVER_CLASSES% RequestHandler.java
-
Compile the servlet as shown in this example for Windows NT:
$ javac -d %SERVLET_CLASSES% StockServlet.java
Configure the server:
- Verify that the servlet classpath points to the
myserver/servletclasses directory in
the weblogic.properties file.
weblogic.httpd.servlet.classpath=weblogic/myserver/servletclasses
where weblogic is the WebLogic Server
installation directory.
- Register StockServlet by adding the
following line to the weblogic.properties file.
weblogic.httpd.register.StockServlet=examples.xml.http.StockServlet
- In this example, the parsers validate the XML data against the
appropriate DTD. You must make the DTDs available to the client application
copying stocktrade.dtd and
traderesult.dtd to your document root.
The document root is the root directory for files that are publically available
on your WebLogic Server. By default it is set to the /myserver/public_html
directory in your WebLogic installation directory. For more details,
see Setting up a document
root.
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/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 XML in
Using
XML with WebLogic Server.
Read more about Servlets in the Developer Guide,
Using
WebLogic HTTP Servlets.
Read more about Enterprise JavaBeans in
BEA
WebLogic Server Enterprise JavaBeans.
Copyright © 1997-2000 BEA Systems, Inc.
All rights reserved.
Last updated
2/9/2000