Java Reference
In-Depth Information
SOAPFault fault = body.getFault();
Name code = fault.getFaultCodeAsName();
String string = fault.getFaultString();
String actor = fault.getFaultActor();
}
If this check determines that you have received a fault, you can retrieve the contents of the
fault object using the
body.getFault
method. Then use the various accessor methods to get
the code, string, and actor values from the fault.
There are a few different methods regarding the fault code.
Getting fault details
Recall that the SOAP fault will contain details in the form of a
javax.xml.soap.Detail
ob-
ject and one or more
DetailEntry
objects onlyin the event that the node was not able to pro-
cess the contents of the body.
Detail
objects are containers for
DetailEntry
objects. There
are only three real methods available on
Detail
; the first gets all of the
DetailEntry
objects
it contains, while the others let you create and add a
DetailEntry
object to a detail, using
either a
Name
or a
QName
:
Detail d = body.getFault().getDetail();
Iterator<DetailEntry> it = d.getDetailEntries();
while (it.hasNext()) {
DetailEntry e = it.next();
System.out.println("Detail Entry = " + e.getValue());
}
Here you get the detail object from the fault so that you can iterate the list of entries. Back on
the server side, entries get created as shown here:
QName name = new QName("http://example.com/quotes",
"getQuote", "e");
//Create the DetailEntry and add it
d.addDetailEntry(name);
In this listing, we've created a fully qualified name to represent the detail entry. This method
both creates and adds the entry.
See Also
Providing a Web Service with SAAJ
to check out the code listing if you want to test this from
a server point of view, and modify it to return your fault under certain circumstances.