Handling SOAP Faults in Java, .NET and Progress OpenEdge

Java

import javax.xml.soap.SOAPElement;
import javax.xml.ws.soap.SOAPFaultException;

public final class SOAPSample {

  public static void main(final String[] args) {

    try {
      ...
    } catch (final SOAPFaultException e) {
      final SOAPElement detail = (SOAPElement) e.getFault().getDetail().getElementsByTagNameNS("urn:soap-fault:details", "FaultDetail").item(0); // replace by the actual detail, if any, this is for the Progress OpenEdge Adapter for Sonic ESB

      final SOAPElement msg = (SOAPElement) detail.getElementsByTagName("errorMessage").item(0);

      throw new Exception(msg.getValue(), e));
    }

  }

}

.NET

using System.Web.Services.Protocols.SoapException;

public sealed class SOAPSample {

  public static void main(const String[] args) {

    try {
      ...
    } catch (const SoapException Ex) {
      throw new Exception(Ex.Detail["FaultDetail", "urn:soap-fault:details"]["errorMessage"].InnerText); // replace by the actual detail, if any, this is for the Progress OpenEdge Adapter for Sonic ESB
    }

  }

}

Progress OpenEdge w/o Detail

IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN
DO:
  RETURN ERROR ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-STRING.
END.

Progress OpenEdge w/ Detail

DEF VAR hFault AS HANDLE.
DEF VAR hDetail AS HANDLE.
DEF VAR hMsg AS HANDLE.

CREATE X-NODEREF hFault.
CREATE X-NODEREF hDetail.
CREATE X-NODEREF hMsg.

...

ERROR-STATUS:ERROR-OBJECT-DETAIL:SOAP-FAULT-DETAIL:GET-NODE(hFault).

IF VALID-HANDLE(hFault) THEN
DO:
  hFault:GET-CHILD(hDetail, 1).

  hDetail:GET-CHILD(hMsg, 1).

  RETURN ERROR hMsg:NODE-VALUE.
END.

Thanks to Luiz and Paulo for the help.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s