background image

The relay Attribute

<< The mustUnderstand Attribute | Overview of SOAP Faults >>
<< The mustUnderstand Attribute | Overview of SOAP Faults >>
U
SING
SOAP F
AULTS
145
You can use the
getMustUnderstand
method to retrieve the value of the
must-
Understand
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 tar-
geted 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 (page 141) (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.