You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mikael Fernandus Simalango <mi...@gmail.com> on 2013/01/23 08:49:40 UTC

[Very Likely Bug] Adding onException into RouteBuilder overwrites assigned route ID with default route ID

Hi,

I spotted somewhat surprising behavior when configuring route builder
via groovy script. If the route builder does not have onException
clause, I can assign route ID to each of the configured routes. This
route IDs will stay intact when I invoke
context.getRouteDefinition("routeID"). However, if onException clause
is introduced into the route builder, the IDs will not be preserved.
Instead, Camel will change the IDs with default route ID (route1,
route2, ...). I tested on 2.10.2 and 2.10.3 and the behaviors are the
same for those versions.

Is this by design or a bug?

I enclose the code to reproduce the behavior below (will attach whole
test project if necessary):
1. Case 1: OnException is absent
*WithoutOnExceptionRouteBuilder.groovy
--------------------------------------------------------------
class WithoutOnExceptionRouteBuilder extends SpringRouteBuilder {

    @Override
    void configure() throws Exception {
        from('direct:nodeA')
            .id('nodeA')
            .to('direct:nodeB')

        from('direct:nodeB')
            .id('nodeB')
            .to('mock:resultB')
    }
}

*TestRouteWithoutOnException.java
-----------------------------------------------------------
public class TestRouteWithoutOnException extends CamelSpringTestSupport {

    @Override
    protected AbstractApplicationContext createApplicationContext() {
        return new
ClassPathXmlApplicationContext("without-onexception-context.xml");
    }

    @Test
    public void testRouteWithoutOnException() throws Exception {
        RouteDefinition routeA = context.getRouteDefinition("nodeA");
        assertNotNull(routeA);

        RouteDefinition routeB = context.getRouteDefinition("nodeB");
        assertNotNull(routeB);
    }
}

2. Case 2: OnException is present
OnExceptionrouteBuilder.groovy
-----------------------------------------------
class OnExceptionRouteBuilder extends SpringRouteBuilder {
    @Override
    void configure() throws Exception {
        onException(Exception.class)
            .handled(true)
            .log('Error occured')

        from('direct:nodeA')
                .id('nodeA')
                .to('direct:nodeB')

        from('direct:nodeB')
                .id('nodeB')
                .to('mock:resultB')
    }
}

TestRouteWithOnException.java
------------------------------------------------
public class TestRouteWithOnException extends CamelSpringTestSupport {

    @Override
    protected AbstractApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("onexception-context.xml");
    }

    @Test
    public void testRouteWithOnException() throws Exception {
        RouteDefinition routeA = context.getRouteDefinition("nodeA");
        assertNotNull(routeA);

        RouteDefinition routeB = context.getRouteDefinition("nodeB");
        assertNotNull(routeB);
    }

    @Test
    public void testRouteWithOnExceptionDefaultId() throws Exception {
        RouteDefinition routeA = context.getRouteDefinition("route1");
        assertNotNull(routeA);

        RouteDefinition routeB = context.getRouteDefinition("route2");
        assertNotNull(routeB);
    }
}


Regards,
Mike

Re: [Very Likely Bug] Adding onException into RouteBuilder overwrites assigned route ID with default route ID

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 23, 2013 at 9:00 AM, Mikael Fernandus Simalango
<mi...@gmail.com> wrote:
> Oh,
>
> This is a very bad call. Thanks Claus. I just checked the source and
> found that id() is only for node ID. Should be much more cautious next
> time.
>

Yeah I have updated the javadoc of the code, to refer people to routeId.

The .id, can be used for settings ids of the various eips/processors
in the routes.
But for setting  the route we need more logic, and hence routeId must
be used instead.



> Regards,
> Mike
>
> On Wed, Jan 23, 2013 at 4:51 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> You should use .routeId to assign the ID of the route.
>>
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: [Very Likely Bug] Adding onException into RouteBuilder overwrites assigned route ID with default route ID

Posted by Mikael Fernandus Simalango <mi...@gmail.com>.
Oh,

This is a very bad call. Thanks Claus. I just checked the source and
found that id() is only for node ID. Should be much more cautious next
time.

Regards,
Mike

On Wed, Jan 23, 2013 at 4:51 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> You should use .routeId to assign the ID of the route.
>
>

Re: [Very Likely Bug] Adding onException into RouteBuilder overwrites assigned route ID with default route ID

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You should use .routeId to assign the ID of the route.


On Wed, Jan 23, 2013 at 8:49 AM, Mikael Fernandus Simalango
<mi...@gmail.com> wrote:
> Hi,
>
> I spotted somewhat surprising behavior when configuring route builder
> via groovy script. If the route builder does not have onException
> clause, I can assign route ID to each of the configured routes. This
> route IDs will stay intact when I invoke
> context.getRouteDefinition("routeID"). However, if onException clause
> is introduced into the route builder, the IDs will not be preserved.
> Instead, Camel will change the IDs with default route ID (route1,
> route2, ...). I tested on 2.10.2 and 2.10.3 and the behaviors are the
> same for those versions.
>
> Is this by design or a bug?
>
> I enclose the code to reproduce the behavior below (will attach whole
> test project if necessary):
> 1. Case 1: OnException is absent
> *WithoutOnExceptionRouteBuilder.groovy
> --------------------------------------------------------------
> class WithoutOnExceptionRouteBuilder extends SpringRouteBuilder {
>
>     @Override
>     void configure() throws Exception {
>         from('direct:nodeA')
>             .id('nodeA')
>             .to('direct:nodeB')
>
>         from('direct:nodeB')
>             .id('nodeB')
>             .to('mock:resultB')
>     }
> }
>
> *TestRouteWithoutOnException.java
> -----------------------------------------------------------
> public class TestRouteWithoutOnException extends CamelSpringTestSupport {
>
>     @Override
>     protected AbstractApplicationContext createApplicationContext() {
>         return new
> ClassPathXmlApplicationContext("without-onexception-context.xml");
>     }
>
>     @Test
>     public void testRouteWithoutOnException() throws Exception {
>         RouteDefinition routeA = context.getRouteDefinition("nodeA");
>         assertNotNull(routeA);
>
>         RouteDefinition routeB = context.getRouteDefinition("nodeB");
>         assertNotNull(routeB);
>     }
> }
>
> 2. Case 2: OnException is present
> OnExceptionrouteBuilder.groovy
> -----------------------------------------------
> class OnExceptionRouteBuilder extends SpringRouteBuilder {
>     @Override
>     void configure() throws Exception {
>         onException(Exception.class)
>             .handled(true)
>             .log('Error occured')
>
>         from('direct:nodeA')
>                 .id('nodeA')
>                 .to('direct:nodeB')
>
>         from('direct:nodeB')
>                 .id('nodeB')
>                 .to('mock:resultB')
>     }
> }
>
> TestRouteWithOnException.java
> ------------------------------------------------
> public class TestRouteWithOnException extends CamelSpringTestSupport {
>
>     @Override
>     protected AbstractApplicationContext createApplicationContext() {
>         return new ClassPathXmlApplicationContext("onexception-context.xml");
>     }
>
>     @Test
>     public void testRouteWithOnException() throws Exception {
>         RouteDefinition routeA = context.getRouteDefinition("nodeA");
>         assertNotNull(routeA);
>
>         RouteDefinition routeB = context.getRouteDefinition("nodeB");
>         assertNotNull(routeB);
>     }
>
>     @Test
>     public void testRouteWithOnExceptionDefaultId() throws Exception {
>         RouteDefinition routeA = context.getRouteDefinition("route1");
>         assertNotNull(routeA);
>
>         RouteDefinition routeB = context.getRouteDefinition("route2");
>         assertNotNull(routeB);
>     }
> }
>
>
> Regards,
> Mike



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen