Tuesday, April 27, 2010

OSB faults transformed into SOAP 1.2 and SOAP 1.1 format

If the client that invokes OSB adheres to the SOAP 1.2 standard, you can always transform the OSB SOAP Fault into the 1.2 standard with this XQuery transformation:


declare namespace xf =
"http://tempuri.org/Transformations/transformations/transformCustomFaultToSoapFault/";
declare namespace soap = "http://www.w3.org/2003/05/soap-envelope";
declare namespace flt = "http://www.bea.com/wli/sb/context";

declare function xf:transformCustomFaultToSoapFault($fault1 as
element(flt:fault))
   as element(soap:Fault) {
       <soap:Fault>
           <soap:Code>
               <soap:Value>soap:Receiver</soap:Value>
           </soap:Code>
           <soap:Reason>
               <soap:Text>{ concat(data($fault1/flt:errorCode) , "-"
, data($fault1/flt:reason)) }</soap:Text>
           </soap:Reason>
           {

               for $location in $fault1/flt:location
               let $node := data($location/flt:node)
               let $pipeline := data($location/flt:pipeline)
               let $stage := data($location/flt:stage)
               let $error-handler := data($location/flt:error-handler)
               let $path := data($location/flt:path)
               return
                   <soap:Node>{ concat($node ,"-" , $pipeline ,"-" ,
$stage ,"-" , $error-handler ,"-" , $path) }</soap:Node>
           }
           {
               for $details in $fault1/flt:details
               return
                   <soap:Detail>{ $details/@* , $details/node() }</soap:Detail>
           }
       </soap:Fault>
};

declare variable $fault1 as element(flt:fault) external;

xf:transformCustomFaultToSoapFault($fault1)

And this is the SOAP 1.1 version:

declare namespace xf =
"http://tempuri.org/Transformations/transformations/transformCustomFaultToSoap11Fault/";
declare namespace ns0 = "http://schemas.xmlsoap.org/soap/envelope/";
declare namespace ns1 = "http://www.bea.com/wli/sb/context";

declare function xf:transformCustomFaultToSoap11Fault($fault1 as
element(ns1:fault))
   as element(*) {
       <ns0:Fault>
       <faultcode>soap:Server</faultcode>
       <faultstring>{ concat($fault1/ns1:errorCode , "-"
,$fault1/ns1:reason) }</faultstring>
       {
       for $node in $fault1/ns1:location/ns1:node
       let  $error-handler := data($fault1/ns1:location/ns1:error-handler)
       let  $path := data($fault1/ns1:location/ns1:path)
       let  $stage := data($fault1/ns1:location/ns1:stage)
       let  $pipeline := data($fault1/ns1:location/ns1:pipeline)
       return
       <faultactor>{ concat($node , "-" , $error-handler , "-" ,
$path , "-" , $stage , "-" , $pipeline) }</faultactor>
       }
       {
       for $details in $fault1/ns1:details
       return
       <detail>{ $details/@* , $details/node() }</detail>
       }
       </ns0:Fault>
};

declare variable $fault1 as element(ns1:fault) external;

xf:transformCustomFaultToSoap11Fault($fault1)

No comments: