background image

Retrieving Fault Information

<< Creating and Populating a SOAPFault Object | SOAPMessage Object >>
<< Creating and Populating a SOAPFault Object | SOAPMessage Object >>

Retrieving Fault Information

SOAPFault fault = body.addFault();
QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE,
"Client");
fault.setFaultCode(faultName);
fault.setFaultString(
"Message does not have necessary info");
Detail detail = fault.addDetail();
QName entryName = new QName(
"http://gizmos.com/orders/", "order", "PO");
DetailEntry entry = detail.addDetailEntry(entryName);
entry.addTextNode(
"Quantity element does not have a value");
QName entryName2 = new QName(
"http://gizmos.com/orders/", "order", "PO");
DetailEntry entry2 = detail.addDetailEntry(entryName2);
entry2.addTextNode(
"Incomplete address: no zip code");
See
"SOAP Fault Example" on page 624
for an example that uses code like that shown in this
section.
The SOAP 1.1 and 1.2 specifications define slightly different values for a fault code.
Table 19­1
lists and describes these values.
TABLE 19­1
SOAP Fault Code Values
SOAP 1.1
SOAP 1.2
Description
VersionMismatch
VersionMismatch
The namespace or local name for a SOAPEnvelope
object was invalid.
MustUnderstand
MustUnderstand
An immediate child element of a SOAPHeader object
had its mustUnderstand attribute set to true, and the
processing party did not understand the element or
did not obey it.
Client
Sender
The SOAPMessage object was not formed correctly or
did not contain the information needed to succeed.
Server
Receiver
The SOAPMessage object could not be processed
because of a processing error, not because of a
problem with the message itself.
N/A
DataEncodingUnknown
A SOAP header block or SOAP body child element
information item targeted at the faulting SOAP node
is scoped with a data encoding that the faulting node
does not support.
Retrieving Fault Information
Just as the SOAPFault interface provides convenience methods for adding information, it also
provides convenience methods for retrieving that information. The following code fragment
shows what you might write to retrieve fault information from a message you received. In the
SAAJ Tutorial
Chapter 19 · SOAP with Attachments API for Java
611