Convert from Fault to Message

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Convert from Fault to Message

Matt Raible
Hello,

Is it possible to convert from returning a SOAP Fault to a SOAP Message when using the CXF component? I'm developing a new system to replace one written with IBM Message Broker 6.1. When faults occur with IBM, error messages are returned that looked the following:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
                <NS1:memberServiceRequest xmlns:NS1="http://ws.app.company.com">
                        <NS1:return>
                                <NS1:errorData>
                                        <Error>Error goes here</Error>
                                </NS1:errorData>
                        </NS1:return>
                </NS1:memberServiceRequest>
        </soapenv:Body>
</soapenv:Envelope>

When an error occurs with Apache Camel, a soap fault is sent back to the client:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
        <soap:Body>
                <soap:Fault>
                        <soap:Code>
                                <soap:Value>soap:Receiver</soap:Value>
                        </soap:Code>
                        <soap:Reason>
                                <soap:Text xml:lang="en">Error goes here</soap:Text>
                        </soap:Reason>
                </soap:Fault>
        </soap:Body>
</soap:Envelope>

I believe sending back a fault is better, but I'd also like to make it possible to be backwards compatible, so the old clients don't need to add fault handling. To do this, I need to convert from a fault to a message.

The following Stack Overflow post seems like it might work, but I'm unsure how to add an out interceptor when the only way I'm definining my CXF service is with "cxf:/foo?serviceClass=...".

http://stackoverflow.com/questions/8066474/how-to-transform-soapfault-to-soapmessage-via-interceptor-in-cxf

Thanks,

Matt
Reply | Threaded
Open this post in threaded view
|

Re: Convert from Fault to Message

Claus Ibsen-2
Hi

Yeah you can use onException and handled = true, and then do a message
translation where you convert the exception into a soap message.

The caused exception is stored as a property on the exchange with key
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html#EXCEPTION_CAUGHT

See for example Camel in Action page 144 onwards.

On Sat, Jul 26, 2014 at 12:07 AM, Matt Raible <[hidden email]> wrote:

> Hello,
>
> Is it possible to convert from returning a SOAP Fault to a SOAP Message when using the CXF component? I'm developing a new system to replace one written with IBM Message Broker 6.1. When faults occur with IBM, error messages are returned that looked the following:
>
> <?xml version="1.0" encoding="utf-8"?>
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>         <soapenv:Body>
>                 <NS1:memberServiceRequest xmlns:NS1="http://ws.app.company.com">
>                         <NS1:return>
>                                 <NS1:errorData>
>                                         <Error>Error goes here</Error>
>                                 </NS1:errorData>
>                         </NS1:return>
>                 </NS1:memberServiceRequest>
>         </soapenv:Body>
> </soapenv:Envelope>
>
> When an error occurs with Apache Camel, a soap fault is sent back to the client:
>
> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
>         <soap:Body>
>                 <soap:Fault>
>                         <soap:Code>
>                                 <soap:Value>soap:Receiver</soap:Value>
>                         </soap:Code>
>                         <soap:Reason>
>                                 <soap:Text xml:lang="en">Error goes here</soap:Text>
>                         </soap:Reason>
>                 </soap:Fault>
>         </soap:Body>
> </soap:Envelope>
>
> I believe sending back a fault is better, but I'd also like to make it possible to be backwards compatible, so the old clients don't need to add fault handling. To do this, I need to convert from a fault to a message.
>
> The following Stack Overflow post seems like it might work, but I'm unsure how to add an out interceptor when the only way I'm definining my CXF service is with "cxf:/foo?serviceClass=...".
>
> http://stackoverflow.com/questions/8066474/how-to-transform-soapfault-to-soapmessage-via-interceptor-in-cxf
>
> Thanks,
>
> Matt



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/