The SOAP Protocol

   

A SOAP Library

The two main approaches to implementing SOAP are as follows :

  • Use a networking library that wraps Java objects in a SOAP network layer. This is similar to a CORBA broker: It takes Java objects and exposes them, as SOAP requests , on a Web server. The reference implementation from IBM (available from http://www.alphaworks.ibm.com) follows this approach.

  • Treat SOAP requests as regular POST requests and write a servlet, or a JSP page, to handle them.

In this chapter, we'll use the second solution. At the time of writing, the SOAP libraries for Java are in the alpha stage and not suitable for inclusion in a book.

However, even if I had had the choice, I would have been inclined to treat SOAP requests as other Web requests. Remember, one of our goals is to build a flexible solution that does not depend directly on the specifics of a Java application.

In the remainder of the chapter, we will write the server to report product availability. We also will write a simple client to test and demonstrate the server. In so doing, we will cover both the wholesaler and the retailer situations.

As always, the focus is on XML, not on building the best stock management system. Indeed, as you will see, I have greatly simplified the inventory management!

Architecture

Figure 9.4 shows the UML model for the client and the server.

Figure 9.4. The architecture of the client and the server.

graphics/09fig04.gif

The various classes in Figure 9.4 are

  • SoapService ”A servlet specialized to process SOAP requests.

  • StockQService ”The inventory management server.

  • XMLWriter ”A helper class to escape XML characters , such as < .

  • StockResponse ”Parses getStock requests and prepares the responses.

  • SoapRequest ”Encapsulates the creation of a SOAP request.

  • StockRequest ”Inherits from SoapRequest and generates the getStock request.

  • Constants ”Holds various constants.

  • StockQClient , StockQPanel ”The inventory management client.

  • SoapException ”Encapsulates SOAP-ENV:Fault .

  • SoapEnvelope ”A SAX filter that parses the SOAP elements. Both SoapRequest and SoapService use it.

SAX's XMLFilter

A filter is both an event handler and an event source : It intercepts events, performs some processing, and generates events of its own. In doing so, it also might remove or add events.

Filters are similar to AWT adapters. Typically you will use one or more filters to pre-process XML documents.

Figure 9.5 illustrates how this works. The document flows through a chain of filters where each filter transforms the document and passes the result to the next stage.

Figure 9.5. Filters are chained to process XML documents.

graphics/09fig05.gif

Filters are typically used to recognize special vocabularies. For example, you can use filters that recognize XLink hyperlinks or use them to decode and validate digital signatures.

In this project, SoapEnvelope is a filter. It processes SOAP-defined elements, such as SOAP-ENV:Envelope and SOAP-ENV:Fault . This frees up the application-specific content handler to concentrate on application-specific elements, such as getProduct .

This supports code reuse (indeed, we use SoapEnvelope on the client and the server). It also isolates the SOAP protocol from the rest of the application, so if SOAP changes, updates will be limited to SoapEnvelope .

   


Applied XML Solutions
Applied XML Solutions
ISBN: 0672320541
EAN: 2147483647
Year: 1999
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net