background image

Messages with Attachments

<< Overviewof SAAJ | SOAPMessage Object >>
<< Overviewof SAAJ | SOAPMessage Object >>

Messages with Attachments

Note ­
Many SAAJ API interfaces extend DOM interfaces. In a SAAJ message, the SOAPPart
class is also a DOM document. See
"SAAJ and DOM" on page 589
for details.
When you create a new SOAPMessage object, it will automatically have the parts that are
required to be in a SOAP message. In other words, a new SOAPMessage object has a SOAPPart
object that contains a SOAPEnvelope object. The SOAPEnvelope object in turn automatically
contains an empty SOAPHeader object followed by an empty SOAPBody object. If you do not need
the SOAPHeader object, which is optional, you can delete it. The rationale for having it
automatically included is that more often than not you will need it, so it is more convenient to
have it provided.
The SOAPHeader object can include one or more headers that contain metadata about the
message (for example, information about the sending and receiving parties). The SOAPBody
object, which always follows the SOAPHeader object if there is one, contains the message
content. If there is a SOAPFault object (see
"Using SOAP Faults" on page 608
), it must be in the
SOAPBody
object.
Messages with Attachments
A SOAP message may include one or more attachment parts in addition to the SOAP part. The
SOAP part must contain only XML content; as a result, if any of the content of a message is not
in XML format, it must occur in an attachment part. So if, for example, you want your message
SOAPMessage (an XML document)
SOAPPart
SOAPEnvelope
SOAPHeader (optional)
Header
Header
SOAPBody
XML Content
or SOAPFault
FIGURE 19­1
SOAPMessage
Object with No Attachments
Overview of SAAJ
Chapter 19 · SOAP with Attachments API for Java
587