Java Reference
In-Depth Information
web services was convenient, contributing to SOAP's early popularity. Moreover, developers
found it easy to use SOAP because XML was already familiar to them, and many platforms
have native XML tools. Quickly, SOAP became a popular way of doing web services.
The SOAP with Attachments API for Java (SAAJ) was created to specifically address the
needs of burgeoning SOAP-based web services developers. It allows you to programmatically
manipulate SOAP envelopes. Using its classes and methods, you can create an envelope, add
a header to the envelope, put data in the header, create a SOAP body, add an XML document
to the SOAP body, and add the body to the envelope. Once your message is complete, you can
ship the complete SOAP message off over HTTP to invoke a web service using a dispatcher.
SAAJ 1.3, which we examine in this chapter, is the foundational API for working with web
services in Java. Every Java EE vendor provides a SAAJ implementation.
NOTE
There is a charter at the W3 for SOAP-JMS. This work is in the early stages as of this writing, but the
idea is to ensure standardize the binding mechanism to interoperability between implementations cre-
ated by web services vendors for SOAP over JMS. You can read more about it at http://www.w3.org/
2007/08/soap-jms-charter.html .
It should be noted, however, that in recent years SAAJ has been superseded by JAX-WS (Java
API for XML Web Services). SAAJ operates at the plumbing level, requiring you to build
every aspect of your SOAP envelopes by hand. The code can get long and somewhat tedious,
and requires in-depth knowledge of the internal structure of the requests and responses you
must work with when invoking web services. JAX-WS reuses SAAJ and acts as a layer of
abstraction above it. Think of SAAJ as the XML view and JAX-WS as the object view of a
message exchange.
Here's an example of a SOAP envelope in XML with HTTP header data:
POST /StockQuote HTTP/1.1
Host: www.soacookbook.com:8080
Content-Type: text/xml; charset="utf-8"
Content-Length: n
SOAPAction: ""
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:GetStockQuote xmlns:m="urn:com:soacookbook">
<ticker>JAVA</ticker>
</m:GetStockQuote>
Search WWH ::




Custom Search