Java Reference
In-Depth Information
Sending and Receiving SOAP Faults
Problem
You want to deal with a web service that has returned a SOAP fault to your SAAJ client.
Solution
Use the SAAJ fault classes to work with the data.
Discussion
When a web service provider throws an exception or error, a SOAP fault is generated. This
bears obvious similarity to exceptions in Java, such as details regarding the exception, human-
readable explanations, and codes.
But there are a number of differences to be aware of. To begin with, there is no linguistic struc-
tural mechanism surrounding the use of faults as there is with Java exceptions. That is, there
is no try-catch mechanism. A fault replacesthe body content of the SOAP response; therefore,
the body element must contain the fault as its only child. Clients must then be prepared to read
a fault from the body in much the same way they are prepared to read the data expected on
a successful invocation. What this means is that the fault is simply data in SOAP. It cannot
reroute or stop processing the way a Java exception can. It is just a message, the same as any-
thing else.
If the message exchange is request-reply, the fault message is returned to the caller as a type
of soap:Fault . If the invocation is one-way, the fault is not returned to the caller.
The only possible child elements of soap:Fault in SOAP 1.1 are the following:
faultstring
A required element. It provides a human-readable explanation of the fault.
faultactor
A required element in the event that an actor is specified. If no actors are specified, the
node is considered the Ultimate Receiver, in which case this element is optional. It is spe-
cified by a URI that identifies the actor causing the fault.
Search WWH ::




Custom Search