onCompletion being triggred, not onException

919 Views Asked by At

This is a varition of the question, I asked in Camel's CXF component not catching onException(Exception.class)

I have implemented the solution which Claus suggested in the above but its not working. I don't understand why onCompletion is being triggered when I've set HandleFault = true at the global level.

I've modified the code A LOT, hence asking the same question but with a few changes.

My Route looks like this: Route 1(camel-cxf endpoint) -> Route 2(direct) -> Route 3(direct). In Route 3, I am throwing a WebApplicationException(I am again wrapping this in MyWSException), which is a runtime exception.

I've set HandleFault to true at the context level.

getContext().setHandleFault(true);

My onException handle at the global level looks like this:

onException(Exception.class, MyWSException.class)
        .process(new Processor(){
            @Override
            public void process(Exchange exchange) throws Exception {
                System.out.println("In onException Exception and IServicesWSException");
            }
        })
        .to("direct:IServicesWSExceptionHandler");

I also have a local one(Route specific), which looks like this.

from("cxf:bean:ordermanagementservice")
        .routeId("ordermanagementservice")
        .startupOrder(2)
        .onException(Throwable.class)
            .handled(true)
            .setBody().simple(PROCESS_RESULT_FAILED)
            .process(new Processor(){
                @Override
                public void process(Exchange exchange) throws Exception {
                    exchange.getIn().setHeader(AuditConstants.AUDIT_MAP_KEY.getValue(), AuditParam.AUDIT_ATTR_STATUS_ORDER);
                }
            })
            .beanRef("AuditManager", "audit")
            .to("direct:IServicesWSExceptionHandler")
            .end()

My onCompletion(Route specific) looks like this.

.onCompletion()
            .setBody().simple(PROCESS_RESULT_SUCCESS)
            .process(new Processor(){
                @Override
                public void process(Exchange exchange) throws Exception {
                    exchange.getIn().setHeader(AuditConstants.AUDIT_MAP_KEY.getValue(), AuditParam.AUDIT_ATTR_STATUS_ORDER);
                }
            })
            .beanRef("AuditManager", "audit")
            .end()

Please help. I apologize if the question seems as a repeat. Very desperate.

Thanks in advance.

0

There are 0 best solutions below