Engineering Full Stack Apps with Java and JavaScript
We have already seen what SOAP faults are and how they are reprecented in the WSDL and SOAP message in the WSDL and SOAP overview notes respectively. Here we will try to consolidate the basic information related to SOAP faults.
Java application exceptions can be mapped to SOAP faults in WSDL/SOAP message.
A SOAP message can have fault elements within it.
Fault elements contain errors and status information.
Fault is an optional element.
If present, it must appear as a child element of the Body element.
It can only appear once in a SOAP message.
The faultcode values must be used in the faultcode element when describing faults:
VersionMismatch
invalid namespace for the SOAP Envelope element
MustUnderstand
An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood
Client
message was incorrectly formed or contained incorrect information
Server
problem with the server so the message could not proceed.
Fault elements may come in places such as:
Within a message element as a part:
<part name="fault" element="tns:MissingName" />
As a child of operation element within portType section.
<fault message="tns:MissingName" name="MissingName" />
As a child of operation element within binding section
<fault name="MissingName">
<soap:fault name="MissingName" use="literal" />
</fault>
If the exception is a checked exception, the corresponding fault details are present in the wsdl. However, if the exception is a unchecked exception (RuntimeException or its subclasses), the corresponding fault details are present in the wsdl. In both cases, the SOAP response will have fault details if an exception is thrown.