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.1. Throwing Server-Side Exceptions in Apache SOAP

The most common way for a service to generate a fault is to throw an exception. Apache SOAP has a mechanism for handling exceptions thrown from the Java class methods that implement service methods. The information in the exception is used to generate corresponding SOAP faults to be sent back to the caller.

The contents of a SOAP fault were covered back in Chapter 2. In that section we discovered that four fault codes could be used in a fault. One of those possibilities is SOAP-ENV:Server, which indicates that a problem occurred while processing the message that was not related to the contents of the request. This fault code could be used if, for example, the back-end server needed to properly process the message was not available. Let's create a simple service that generates the simplest of faults so that we can see the basic mechanism used in Apache SOAP. Here's the javasoap.book.ch7.SampleFaultService class that implements the service urn:SampleFaultService:

package javasoap.book.ch7;
import org.apache.soap.SOAPException;
public class SampleFaultService {
   public SampleFaultService(  ) {
   }
   public int generateFault(  ) 
        throws Exception {
      // something bad must have happened...
      throw new Exception(  );
   }
}

The declaration of the generateFault( ) method indicates that it may throw an instance of java.lang.Exception. In fact, that's all it does. We're simulating what would happen if the service method received a call that could ...

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