4

I have a camel-cxf webservice up. I use to handle all SOAP Faults in the CXF's SOAP Fault Interceptor mechanism. That is working well.

I thought that its better to handle Exception thrown at the Camel layer at the same layer and wrote a simple onException scenario like this:

onException(Exception.class). to("direct:MyWSExceptionHandler");

Whenever a custom exception is thrown, I was expecting the onException to kick in(Remember I also have a SOAP Fault Interceptor too), but it doesn't. The CXF is taking over and the message is going through the Interceptors, rather than the Camel Route.

Is this the expected way, or am I doing something wrong?

My CXF fault interceptor looks like this:

@Component("SOAPFaultInterceptor")
public class SOAPFaultInterceptor extends AbstractPhaseInterceptor {

    public SOAPFaultInterceptor() {
        super(Phase.MARSHAL);
    }

    public void handleMessage(Message message) throws Fault {
     // The message is coming here directly, instead of going to the route defined by onException.
    }
}

Can someone please tell how to fix this? I don't want Exception generated at the Camel layer to leave that layer without being handled..

Thanks in advance.

Anoop Hallimala
  • 625
  • 1
  • 11
  • 25

1 Answers1

4

Camel's onException only triggeres if there is an exception. A SOAP Fault is represented as a Message with the fault flag = true.

What you can do is to set handleFault=true on CamelContext, then it will turn SOAP fault messages into an exception that the onException can react upon.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Thank you so much, Claus. I remember reading about it now. I admire your work with Camel and that makes me a fan, I suppose :) Great work, indeed.. Thanks. – Anoop Hallimala May 11 '13 at 12:19
  • 1
    Hi Claus, This is not working. I've a very complex route Route1->Route2->Route3(this is where the exception is thrown). I am throwing an instance of WebApplicationException, which is a Runtime Exception. I've designed global onException(Exception.class, MyWSException.class) AND a local one. onCompletion is being triggered, even though I set HandleFault(true). I don't understand why onCompletion is being trigerred when clearly onException should be. Please guide. – Anoop Hallimala May 17 '13 at 08:21
  • 1
    Hi, I am facing a very similar issue. I am using Apache Camel 2.12.2 APIs for a CXF web service. I have set camelContext's handleFault=true, I have .doTry() with .doCatch() around my web service route's .to() call and yet I am not able to handle SOAPFaults myself within my web service's route configs. I have also tried .errorHandler(deadLetterChannel("wmq:SOME_QUEUE")) but still, only the PhaseInterceptorChain seems to be handling the faults. Does this mechanism actually work as expected? Are there any examples anywhere showing this handleFault=true mechanism at work? – Going Bananas May 08 '14 at 14:22