background image

SAAJ and DOM

<< Messages with Attachments | SOAP messages and SOAP connections >>
<< Messages with Attachments | SOAP messages and SOAP connections >>
122
SOAP
WITH
A
TTACHMENTS
API
FOR
J
AVA
If a
SOAPMessage
object has one or more attachments, each
AttachmentPart
object must have a MIME header to indicate the type of data it contains. It may
also have additional MIME headers 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
SOAP-
Part
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 Con-
tent to the SOAPPart Object (page 134)
and Adding a Document to the SOAP
Body (page 136).
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