Try OpenEdge Now
skip to main content
Web Services
Developing a Java Client to Consume OpenEdge SOAP Web Services : Developing the Axis client application : Handling errors on the client
 

Handling errors on the client

To understand how to handle SOAP fault messages returned by the WSA, first note that the <FaultDetail> element is described in the interface Java class, servicehost/FaultDetail.java. For example:
public class FaultDetail {
   java.lang.String errorMessage;
   java.lang.String requestID;
   ...
}
Place a try...catch block around any code that accesses the Web server and catch the AxisFault exception.
This is an example of Axis client code to catch a SOAP fault (an AxisFault exception):
try
{
    // code to Access the Web Service
}
catch (AxisFault e)
{
    // Get the (single) child element of the SOAP Fault <detail> element,
    // the <FaultDetail> element.

    Element[] faultDetails = e.getFaultDetails( );
    if (faultDetails.length > 0)
    {
        // Now get the contents of the <FaultDetail> element,
        //    <errorMessage> and <requestID>.

        Node     faultDetailElem = faultDetails[0].getFirstChild( );
        String   detailErrorMsg =
           faultDetailElem.getFirstChild( ).getNodeValue( );
        System.err.println("Exception errorMessage: " + detailErrorMsg);
        Node     requestIDElem = faultDetailElem.getNextSibling( );
        String   requestID = requestIDElem.getFirstChild( ).getNodeValue( );
        System.err.println("Exception requestID : " + requestID);
    }
}
Caution: In any catch block where you exit the program, you must release all Web service objects you created in the program.