Hi Camel riders,

I'm trying to figure out why onException is not triggerd in the following
route. The solution I found is to use try-catch instead, but I'd prefer to
have it work only with errorHandler and onException


import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class ErrorTest extends CamelTestSupport {

    @Test
    public void testErrorIsThrown() throws Exception {

        getMockEndpoint("mock:foundException").expectedMessageCount(1);

        try {
            template.sendBody("direct:start", "test");
            fail("Propagate exception back to consumer");
        } catch (Exception e) {
        }
        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {

                from("direct:start")
                        .to("direct:internal")
                            .onException(Exception.class)
                            .to("mock:foundException");

                from("direct:internal")

.errorHandler(defaultErrorHandler().maximumRedeliveries(2))
                        .throwException(new RuntimeException())
                        .to("mock:never");
            }
        };
    }
}



-- 
Bilgin Ibryam

Apache Camel & Apache OFBiz committer
Blog: ofbizian.com
Twitter: @bibryam <https://twitter.com/bibryam>

Author of Instant Apache Camel Message Routing
http://www.amazon.com/dp/1783283475

Reply via email to