O'Reilly logo

Java SOA Cookbook by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 structural mechanism surrounding the use of faults as there is with Java exceptions. That is, there is no try-catch mechanism. A fault replaces the 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 anything 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required