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.3. Throwing and Catching Exceptions in GLUE

The concepts covered for faults and exceptions in Apache SOAP are similar to those used in GLUE, although some of the techniques are different. Actually, GLUE has a few ways of dealing with exceptions, so if you're interested in all the possibilities, I encourage you to read the GLUE user's guide; we're going to cover only one technique here.

Let's skip the basics and get right into an example that returns faults with a detail section. GLUE includes its own SOAP exception class called electric.net.soap.SOAPException. It's not the same as the Apache SOAPException, so don't confuse the two. GLUE's SOAPException allows you to set the fault code, fault string, fault actor, and details, and has several constructors using a variety of combinations of these fault element values. Therefore, you don't have to write a fault handler to get the detail information into the fault; just throw an instance of SOAPException with the appropriate values. Let's create a service called urn:AnotherFaultService and implement it with the AnotherFaultService class:

package javasoap.book.ch7; import electric.net.soap.SOAPException; import electric.xml.*; public class AnotherFaultService { public int generateFault( ) throws SOAPException { Element elem = new Element("detail"); Element sub = elem.addElement("reasonCode"); sub.addText("199"); sub = elem.addElement("reasonDescription"); sub.addText("Power Outage"); sub = elem.addElement("alternateProvider"); ...

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