background image

SAAJ Connections

<< SOAPMessage Object | SAAJ Tutorial >>
<< SOAPMessage Object | SAAJ Tutorial >>

SAAJ Connections

to identify it or to give its location. These headers are optional but can be useful when there are
multiple attachments. When a SOAPMessage object has one or more AttachmentPart objects,
its SOAPPart object may or may not contain message content.
SAAJ and DOM
The SAAJ APIs extend their counterparts in the org.w3c.dom package:
The Node interface extends the org.w3c.dom.Node interface.
The SOAPElement interface extends both the Node interface and the org.w3c.dom.Element
interface.
The SOAPPart class implements the org.w3c.dom.Document interface.
The Text interface extends the org.w3c.dom.Text interface.
Moreover, the SOAPPart of a SOAPMessage is also a DOM Level 2 Document and can be
manipulated as such by applications, tools, and libraries that use DOM. For details on how to
use DOM documents with the SAAJ API, see
"Adding Content to the SOAPPart Object" on
page 599
and
"Adding a Document to the SOAP Body" on page 600
.
SAAJ Connections
All SOAP messages are sent and received over a connection. With the SAAJ API, the connection
is represented by a SOAPConnection object, which goes from the sender directly to its
destination. This kind of connection is called a point-to-point connection because it goes from
one endpoint to another endpoint. Messages sent using the SAAJ API are called
request-response messages. They are sent over a SOAPConnection object with the call method,
which sends a message (a request) and then blocks until it receives the reply (a response).
SOAPConnection
Objects
The following code fragment creates the SOAPConnection object connection and then, after
creating and populating the message, uses connection to send the message. As stated
previously, all messages sent over a SOAPConnection object are sent with the call method,
which both sends the message and blocks until it receives the response. Thus, the return value
for the call method is the SOAPMessage object that is the response to the message that was sent.
The request parameter is the message being sent; endpoint represents where it is being sent.
SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = factory.createConnection();
. . .// create a request message and give it content
java.net.URL endpoint = new URL(
"http://fabulous.com/gizmo/order");
SOAPMessage response = connection.call(request, endpoint);
Overview of SAAJ
Chapter 19 · SOAP with Attachments API for Java
589