camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eirilwan <eiril...@gmail.com>
Subject global onException handler with different route builders
Date Wed, 25 Nov 2009 08:46:52 GMT

Hi

I have a problem. I recently upgraded from Camel 2.0-M2 to Camel 2.0.0,
which broke some of my integration tests. I have narrowed the problem down
to a simple example. 

I Have 2 routebuilders, BaseRoute and FaultRoute. BaseRoute listens to a
direct:start, and sends it forward to direct:thrower which is defined in
FaultRoute. In 2.0-M2, errors thrown from FaultRoute got caught by the
global onException handler defined in BaseRoute. But in 2.0.0 this exception
is not caught, and thrown to the sender. Is the onException clause local
within the routebuilder? If so, is it possible to define a global exception
handler? 

The code below contains the example with two tests describing the situation. 

Regards
Eirik L. Wang


Example code:
@Component("baseRouteBuilder")
public class BaseRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        onException(TestCustomException.class).handled(true);

        //does not work
        from("direct:start").to("direct:thrower");

        //Works
        from("direct:start2").to("direct:thrower2");
        from("direct:thrower2").throwException(new
TestCustomException("test"));

    }
}

@Component("faultRouteBuilder")
public class FaultRoute extends RouteBuilder{

    @Override
    public void configure() throws Exception {
        from("direct:thrower").throwException(new
TestCustomException("message"));
    }
}


Spring-context: applicationContext-camel-routes.xml
<context:component-scan base-package="test.routes"/>
    <context:annotation-config/>

    <!--suppress UnparsedCustomBeanInspection -->
    <camel:camelContext id="camel">
        <camel:routeBuilder ref="baseRouteBuilder"/>
        <camel:routeBuilder ref="faultRouteBuilder"/>
    </camel:camelContext>


Test: 

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations =
"classpath:applicationContext-camel-routes.xml")
public class BaseRouteTest {
    @Produce(uri = "direct:start")
    protected ProducerTemplate startConsumer;

    @Produce(uri = "direct:start2")
    protected ProducerTemplate start2Consumer;

    @Test
    public void shouldCatchExceptionButDoesNot(){
        startConsumer.sendBody("test");
    }

    @Test
    public void shouldCatchException(){
        start2Consumer.sendBody("test");
    }


-- 
View this message in context: http://old.nabble.com/global-onException-handler-with-different-route-builders-tp26509205p26509205.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message