background image

Using SOAP Faults

<< The role Attribute | Overviewof SOAP Faults >>
<< The role Attribute | Overviewof SOAP Faults >>

Using SOAP Faults

This fragment produces the following XML:
<ns:confirmationDesk
xmlns:ns=
"http://gizmos.com/NSURI"
SOAP-ENV:actor=
"http://gizmos.com/confirmations"
SOAP-ENV:mustUnderstand=
"1"/>
You can use the getMustUnderstand method to retrieve the value of the mustUnderstand
attribute. For example, you could add the following to the code fragment at the end of the
preceding section:
System.out.println(
"mustUnderstand is " + headerElement.getMustUnderstand());
The relay Attribute
The SOAP 1.2 specification adds a third attribute to a SOAPHeaderElement, relay. This
attribute, like mustUnderstand, is a boolean value. If it is set to true, it indicates that the SOAP
header block must not be processed by any node that is targeted by the header block, but must
only be passed on to the next targeted node. This attribute is ignored on header blocks whose
mustUnderstand
attribute is set to true or that are targeted at the ultimate receiver (which is the
default). The default value of this attribute is false.
For example, you could set the relay element to true for the billingHeader in the code
fragment in
"The actor Attribute" on page 605
(also changing setActor to setRole):
QName billing = new QName(nameSpaceURI,
"billingDesk", nameSpace);
SOAPHeaderElement billingHeader = header.addHeaderElement(billing);
billingHeader.setRole(
"http://gizmos.com/billing");
billingHeader.setRelay(true);
This fragment produces the following XML:
<ns:billingDesk
xmlns:ns=
"http://gizmos.com/NSURI"
env:relay=
"true"
env:role=
"http://gizmos.com/billing"/>
To display the value of the attribute, call getRelay:
System.out.println(
"relay is " + headerElement.getRelay());
Using SOAP Faults
In this section, you will see how to use the API for creating and accessing a SOAP fault element
in an XML message.
SAAJ Tutorial
The Java EE 5 Tutorial · September 2007
608