Java Reference
In-Depth Information
Code
Classifies faults according to one of several local names and provides a context for the
detail items that may follow
Of these, only Code and Reason are mandatory. SOAP 1.2 defines one additional fault code
than SOAP 1.1, as you can see in Table 5-2 . You'll note that some of the codes have survived
to SOAP 1.2, and others have been renamed.
Table5-2.SOAP 1.2 fault codes
Local name
Purpose
DataEncodingUnknown SOAP 1.2 only. The node throwing the fault can't read the data encoding used by
the message.
Called Client in SOAP 1.1.
Sender
Called Server in SOAP 1.1.
Receiver
Same as SOAP 1.1.
MustUnderstand
Same as SOAP 1.1.
VersionMismatch
Sending a fault
Now that you're familiar with the basic structure of a fault, let's look at how to put one to-
gether on the server side.
The basic idea is to get the body from the message, and call the addFault method. You can
use additional methods defined on the SOAPFault object to add a name, code, actor, and fault
string, as shown here:
//SOAP 1.1
Name codeName = soapFactory.createName("Server", "",
SOAPConstants.URI_NS_SOAP_ENVELOPE);
fault.setFaultCode(codeName);
fault.setFaultActor("http://soacookbook.com/books");
fault.setFaultString("The remote susbsytem host is unavailable.");
Getting fault information
Because of the lack of structured exception handling, and the fact that fault content replaces
body content, you need a way to check if a fault occurred. To do so, use the convenience meth-
od, SOAPBody.hasFault :
SOAPBody body = responseMessage.getSOAPBody();
if (body.hasFault()) {
Search WWH ::




Custom Search