2
votes

I am using Java DSL to configure the routes. I have a route similar to what's been given below.

    RouteBuilder builder = new RouteBuilder() {
        public void configure() {
           // onException(Exception.class).bean("bean");

            onException(Exception.class).to("anotherProcessor");

            from("queue:a").bean("someBean").to("processor");
        }
    };

How do i blow up the exception after doing some activity? On exception, I tried configuring a processor and a bean to rethrow the exception. Either way, camel is setting the exception to exchange but not blowing up the exception.

I am doing this in a junit test case. I am handling the exception using onException processor. Inside the processor, i am doing my assertions. The assertion errors are handled automatically by camel and the tests are not getting marked as pass/fail.

1
What do you mean by "blowing up the exception"? What kind of behavior do you want to achieve? - Ralf
I have a processor onException and if it throws any error or exception, the control goes to DelegateSyncProcessor and the exception/error is not bubbled to the client. - l a s
Are you using the Camel JMS component? If yes, then you need to set transferException=true (see documentation). You also might have to call .handled(false) in your onException statement. I don't remember what the Camel default is if the error is handled by a processor. Might be that Camel marks the exception as handled by default. - Ralf

1 Answers

0
votes
from(CONSUMER)
    .doTry()
    .doCatch(SocketTimeoutException.class,Exception.class)
            .beanRef("ErrorProcessor","processErrorMessage")
            .to("freemarker:ErrorResponseTransformer.ftl")
    .end()
    .to(PRODUCER)

Try-catch

onException(Exception.class)
        .handled(true)
        .process(new Processor() {
            public void process(Exchange e) throws Exception {
                helper.processErrorMessage(e);
                log.info("Response error: "
                        + MessageHelper.extractBodyAsString(e.getIn()));
                log.info("Response error: "
                        + MessageHelper.extractBodyAsString(e.getOut()));
            }
        });

on Exception Handle exception and process it as a response error message to display. You can even put a .to(ERRORDESTINATION) or wiretap to continue normal flow.

or use camel's errorHandler.

Hope this helps.