camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Jiang <willem.ji...@gmail.com>
Subject Re: How to extract SOAPFault details from CXF
Date Wed, 02 Jun 2010 14:13:42 GMT
attilav wrote:
> Hi Willem,
> 
> thanks for your help!
> 
> 
> 
> willem.jiang wrote:
>>
>>> 1. My primary concern is, that in the case the server returns a
>>> SOAPFault, I
>>> can not extract the details of the fault. The SoapFault is thrown, and
>>> the
>>> corresponding onException clause is triggered, but according to the log
>>> below, the detail attribute is null.
>> As the detail is a element , if you want to get the message detail, you 
>> should call fault.getDetail().getTextContent().
>>
> ah, my bad. I mistook the [detail: null] output of the getDetail() as a null
> detail, and dindn't go any further :(
> 
> 
> willem.jiang wrote:
>>> 2. A second remark is, that the handleFault()  does not seem to have any
>>> effect on the flow. The SoapFault is thrown regardless of it. I expected
>>> it
>>> to work similar to jbi faults: when it is present throw the exception,
>>> otherwise just set the EXCEPTION_CAUGHT property on the exchange, and let
>>> the flow continue.
>> handleFault() just turn a fault message into exception so we can 
>> leverage Camel error handler to deal with it.
>> As camel-cxf just throw the exception out and didn't put the exception 
>> into the fault message as JBI does, using the handleFault() will not 
>> change anything in your case.
>>
> Well, that is my point. 
> In the case of jbi I was told that for a jbi fault, no exception is thrown,
> and the causing jbi FaultException is set as a property of the exchange
> (rather than as the exception of the exchange) -- so that one may continue
> routing.
> In an analog manner I expected cfx tu put the exception into the fault
> message, and not to throw an SoapFault exception. Isn't this some kind
> inconsistency? Or am I getting it all wrong?
> 
> On the other hand, if cxf does throw the SoapFault, shouldn't it set the
> exception of the exchange (exchange.getException(), exchange.getFault()) ?
> 
> 
The SoapFault is thrown from CxfProducer, and it's a common Camel
practices. You can put SoapFault into the outMessage body like this

                  from("direct:start")
                     .onException(SoapFault.class)
                         .maximumRedeliveries(0)
                         .handled(true)
                         .process(new Processor() {
                             public void process(Exchange exchange)
throws Exception {
                                 SoapFault fault =

exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
                                 exchange.getOut().setFault(true);
                                 exchange.getOut().setBody(fault);
                             }

                         })
                         .end()
                     .to(SERVICE_URI);

You can find the unit test here[1]

[1]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomizedExceptionTest.java

> 
> 
> 
>> 3. My third question, isn't there a simple way to send a SOAP message with
>> CXF? I mean I have the SOAPBody prepared (as string or
>> org.w3c.dom.Document), and I expect cxf to wrap it in an envelope, and
>> also
>> return a SOAPBody. Do I really have to do the cumbersome payload
>> conversions
>> prior and after the request?
>>
> You may take a look at the camel-soap[1] component, which just wrap the 
> soap message for you and don't touch any other CXF stack, you can use it 
> as a DataFormat[2]
> [1]http://camel.apache.org/soap.html
> [2]http://camel.apache.org/data-format.html
> 
> nice feature for 2.3! Too bad I'm stuck with camel2.2 as of
> servicemix-camel-2010.01 :(
> 
It should be easy to replace the camel-2.2.0 with camel-2.3.0 if you can
build the servicemix-camel component yourself.
> regards,
> attilav
> 

Willem


Mime
View raw message