O'Reilly logo

Java and SOAP by Robert Englander

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

7.2. Creating a Fault Listener in Apache SOAP

To populate a fault with a detail element, we need to create a new class for fault listening by implementing the org.apache.soap.server.SOAPFaultListener interface. This interface defines a method called fault( ), which is called by the Apache SOAP framework when a fault needs to be generated. The only parameter passed to this method is an instance of org.apache.soap.server.SOAPFaultEvent,[1] which carries an instance of org.apache.soap.Fault and the SOAPException that was thrown by the service method. The fault object contains methods for getting and setting the fault code, fault string, fault actor, and details. This is the object we want to manipulate to provide detail information.

[1] If you're familiar with the JavaBeans patterns for events you should recognize this naming convention. The event that has taken place is a SOAPFault. The listener interface is named by appending Listener to the event name, and the object carrying the event information is named by appending Event.

But before we create the fault listener, we need a mechanism for providing it with the detail data. We don't have a direct path from our service methods to the fault listener, but we can take advantage of the exception mechanism. Since we've seen that the SOAPException that gets thrown by the service method is available to the fault listener, we can inherit from SOAPException and create a new class that meets our needs. But before we do that, we need a ...

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