Monday, April 26, 2010

SOAP Fault in OSB

see also http://www.javamonamour.org/2010/07/osb-error-handling-fault.html

this is what the WS method does:

    @WebMethod(action="generateFault1")
    public void generateFault1() throws Exception {
        throw new Exception("ciao1");
    }

and this is what the method generates when run in OSB

    <soapenv:Envelope      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
    <soapenv:Fault>
    <faultcode>soapenv:Server</faultcode>
    <faultstring>BEA-380001: Internal Server Error</faultstring>
    <detail>
    <con:fault      xmlns:con="http://www.bea.com/wli/sb/context">
    <con:errorCode>BEA-380001</con:errorCode>
    <con:reason>Internal Server Error</con:reason>
    <con:location>
    <con:node>RouteTo_BSPVWS01</con:node>
    <con:path>response-pipeline</con:path>
    </con:location>
    </con:fault>
    </detail>
    </soapenv:Fault>
    </soapenv:Body>
    </soapenv:Envelope>


This is the structure of the fault element




This is how to declare the faults generated by an operation:

http://www.w3.org/TR/wsdl#_soap:fault

here in more details
http://docs.sun.com/app/docs/doc/821-0015/ggeip2?a=view

A really interesting article defining Business Faults versus System Faults, and Fault handling Policies
http://www.troubleshootingwiki.org/Handling_errors_in_SOA_based_systems

nothing new really, in the Java world there are the same concepts, much better defined.


The fascinating thing is that in the Error Handler you have all sort of information disseminated in 2 places: the $fault variable and the $body variable

$fault: <con:fault xmlns:con="http://www.bea.com/wli/sb/context">
  <con:errorCode>BEA-380001</con:errorCode>
  <con:reason>Internal Server Error</con:reason>
  <con:location>
    <con:node>RouteNode1</con:node>
    <con:path>response-pipeline</con:path>
  </con:location>
</con:fault>>

$body: <env:Body xmlns:
env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Fault>
    <faultcode>env:Server</faultcode>
    <faultstring>ciao2</faultstring>
    <detail>
      <java:PierreException xmlns:java="java:com.pierre.exceptions"/>
    </detail>
  </env:Fault>
</env:Body>>

(the exception being thrown is new com.pierre.exceptions.PierreException("ciao2")

The complete stacktrace is missing though...

No comments: