All Examples  XML Examples 

package examples.xml.http

XML-HTTP example package and classes

  • Client
  • Servlet
  • Helper
  • DTDs
  • about this example

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

    1. This examples uses the TraderBean from the StatefulSession EJB example. You must first build and deploy this EJBean before running this example.
    2. Set up your development shell, as described in Setting up your environment.
    3. Compile the client as shown in this example for Windows NT:
        $ javac -d %CLIENT_CLASSES%
    4. Compile RequestHandler as shown in this example for Windows NT:
        $ javac -d %SERVER_CLASSES%
    5. Compile the servlet as shown in this example for Windows NT:
        $ javac -d %SERVLET_CLASSES%

    Configure the server:

    1. Verify that the servlet classpath points to the myserver/servletclasses directory in the file.
      where weblogic is the WebLogic Server installation directory.
    2. Register StockServlet by adding the following line to the file.
    3. 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:

    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/StockServlet
      Host name of the WebLogic Server
      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