问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/16481466/camels-cxf-component-not-catching-onexceptionexception-class