camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "S. Ali Tokmen" <savas-ali.tok...@bull.net>
Subject Re: CXF consumer: fault handling
Date Thu, 05 Aug 2010 11:35:06 GMT
Hello

On 05/08/2010 13:26, Willem Jiang wrote:
> If you just throw an normal exception, you may need to set the Fault 
> detail yourself.
> As CxfConsumer doesn't know how to deal with it.

Well... It would have with the code I have sent before.

Basically, with that modification, when the CxfConsumer receives an 
exception, it looks it that exception has a @WebFault annotation. In 
that case, after having created the Fault object, it retrieves the 
details of the @WebFault (namespace and name) to put them as the Fault's 
details.

Sinppet:

     Throwable cause = exchange.getProperty(
         Exchange.EXCEPTION_CAUGHT, Throwable.class);

     Fault fault = new Fault(cause);
     if (cause.getMessage() != null) {
         fault.setMessage(cause.getMessage());
     } else {
         // The exception has no message (for example, NPEs don't)
         // Set Fault message to exception type
         fault.setMessage(cause.getClass().getSimpleName());
     }

     WebFault faultAnnotation =
         cause.getClass().getAnnotation(WebFault.class);
     if (faultAnnotation != null) {
         // This exception is a WebFault. Add details.
         Element detail = fault.getOrCreateDetail();
         Element faultDetails = detail.getOwnerDocument().createElementNS(
             faultAnnotation.targetNamespace(), faultAnnotation.name());
         detail.appendChild(faultDetails);
     }

     exchange.getOut().setFault(true);
     exchange.getOut().setBody(fault);

But anyways, this is only a minor evolution.

Cheers

-- 

S. Ali Tokmen
savas-ali.tokmen@bull.net

Office: +33 4 76 29 76 19
GSM:    +33 66 43 00 555

Bull, Architect of an Open World TM
http://www.bull.com



Mime
View raw message