More Complex Message Exchange

So far you have looked at simple message exchange. This section examines other issues when exchanging SOAP messages.

Headers and Attachments

As well as XML information in the SOAP body, SAAJ allows you to add and retrieve header information and attachments.

The SOAPHeader can be obtained from the SOAPEnvelope with the getHeader method. If you are creating a message, you can populate the header using the addHeaderElement method that returns a SOAPHeaderElement. You can then add text or attributes to this header element, as shown in the following:

 Name txName = envelope.createName("TransactionId", "acme", "http://acme.com/transactions"); SOAPHeaderElement headerElement = header.addHeaderElement(txName); headerElement.addTextNode("78d2892ea8af625323c7"); ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.