You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Nikola Glidzic <ni...@ikor.one> on 2023/01/23 13:11:31 UTC

BUG - RouteDefinition doesnt have routeId when using REST DSL

Hello Camel crew,

I will explain in details what I have discovered, how to reproduce it and potential idea for fixing the issue. I am using Camel version 3.18.4.

In my code, I have Camel unit tests where I extend CamelTestSupport. I am testing routes from one single RouteBuilder object which has some simple routes, but it has also routes created with REST DSL.
What I am doing in this test is simply mocking these REST DSL routes in my test, hence I am using AdviceWith:

AdviceWith.adviceWith( "myRestRouteId", context, new AdviceWithRouteBuilder() {
          @Override
          public void configure() throws Exception {
            replaceFromWith("direct: myRestRouteIdTesting");
          }
    });

The problem is that Advice will search for a RouteDefinition with given id "myRestRouteId", but it can't find it and I get following exception: java.lang.IllegalArgumentException: Cannot advice route as route with id: myRestRouteId does not exists This exception happens only for REST DSL routes.

I have an explanation what happens and what should be a fix. Let me explain:

Before starting the routes in the Camel context, what happens first is that all RouteDefinitions will be collected. But REST DSL routes will be collected as VerbDefinition-s. So at the beginning given routeId will be stored in a VerbDefinition object. After that in a class RestDefinition there is a method asRouteDefinition() which calls addRouteDefinition() method.
Then addRouteDefinition() will actually loop through all VerbDefinition-s and will transform them one by one in RouteDefinition-s. But here it is missed to set routeId for RouteDefinition.

My proposal for fix would be just to add a single line in mentioned transformation loop:  route.setId(verb.getId());

All of this happens before Camel Context starts the routes. Problem was well hidden because later during the route starting phase, there is forceAssignIds() method in RouteDefinitionHelper class, which will take routeId from VerbDefinition and assign it to proper RouteDefinition. And then at the end as final result, when all routes are started, you will have your route id for your REST DSL route.
But semantically looking, route id should be assigned to RouteDefinition earlier, during lets call it "reading and building RouteDefinitions phase".

Anyway the problem exists when you try to test routes and use AdviceWith.
I think this is a bug and fix is necessary since AdviceWith currently doesn't work for all routes.

What you think about this? Should I open Jira ticket for this?
Just to mention that I already tried this fix and AdviceWith worked as expected.

Kind Regards,
Nikola Glidzic

RE: BUG - RouteDefinition doesnt have routeId when using REST DSL

Posted by Nikola Glidzic <ni...@ikor.one>.
Wow nice, I am glad that route part is back to REST DSL!

Thank you Claus for help and answer!

Kind Regards,
Nikola Glidzic

Re: BUG - RouteDefinition doesnt have routeId when using REST DSL

Posted by Claus Ibsen <cl...@gmail.com>.
Camel 3.19 (CAMEL-18057) added routeId in rest-dsl.


On Fri, Jan 27, 2023 at 12:17 PM Nikola Glidzic <ni...@ikor.one>
wrote:

> Hi Claus,
>
> Thanks for answer.
>
> Actually, you can't do that anymore, because writing a route part in REST
> DSL is not possible anymore and routeId("myId") comes from RouteDefinition,
> but not from RestDefinition.
>
> We used Camel version 3.15.0 before and there we utilized route() and
> routeId("myId") in REST DSL, now we switched to 3.18.4 and there is only
> .id("myId") option for REST DSL.
> That big change for REST DSL happened somewhere between versions 3.15.0
> and 3.18.0. You can inspect that in RestDefinition class.
>
> So currently, the problem explained in my first email exists.
>
> Kind Regards,
> Nikola Glidzic
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

RE: BUG - RouteDefinition doesnt have routeId when using REST DSL

Posted by Nikola Glidzic <ni...@ikor.one>.
Hi Claus,

Thanks for answer.

Actually, you can't do that anymore, because writing a route part in REST DSL is not possible anymore and routeId("myId") comes from RouteDefinition, but not from RestDefinition.

We used Camel version 3.15.0 before and there we utilized route() and routeId("myId") in REST DSL, now we switched to 3.18.4 and there is only .id("myId") option for REST DSL.
That big change for REST DSL happened somewhere between versions 3.15.0 and 3.18.0. You can inspect that in RestDefinition class.

So currently, the problem explained in my first email exists.

Kind Regards,
Nikola Glidzic

Re: BUG - RouteDefinition doesnt have routeId when using REST DSL

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

In rest-dsl you can/should use routeId("myId") anot not id("myId") to
specify the route id



On Mon, Jan 23, 2023 at 2:11 PM Nikola Glidzic <ni...@ikor.one>
wrote:

> Hello Camel crew,
>
> I will explain in details what I have discovered, how to reproduce it and
> potential idea for fixing the issue. I am using Camel version 3.18.4.
>
> In my code, I have Camel unit tests where I extend CamelTestSupport. I am
> testing routes from one single RouteBuilder object which has some simple
> routes, but it has also routes created with REST DSL.
> What I am doing in this test is simply mocking these REST DSL routes in my
> test, hence I am using AdviceWith:
>
> AdviceWith.adviceWith( "myRestRouteId", context, new
> AdviceWithRouteBuilder() {
>           @Override
>           public void configure() throws Exception {
>             replaceFromWith("direct: myRestRouteIdTesting");
>           }
>     });
>
> The problem is that Advice will search for a RouteDefinition with given id
> "myRestRouteId", but it can't find it and I get following exception:
> java.lang.IllegalArgumentException: Cannot advice route as route with id:
> myRestRouteId does not exists This exception happens only for REST DSL
> routes.
>
> I have an explanation what happens and what should be a fix. Let me
> explain:
>
> Before starting the routes in the Camel context, what happens first is
> that all RouteDefinitions will be collected. But REST DSL routes will be
> collected as VerbDefinition-s. So at the beginning given routeId will be
> stored in a VerbDefinition object. After that in a class RestDefinition
> there is a method asRouteDefinition() which calls addRouteDefinition()
> method.
> Then addRouteDefinition() will actually loop through all VerbDefinition-s
> and will transform them one by one in RouteDefinition-s. But here it is
> missed to set routeId for RouteDefinition.
>
> My proposal for fix would be just to add a single line in mentioned
> transformation loop:  route.setId(verb.getId());
>
> All of this happens before Camel Context starts the routes. Problem was
> well hidden because later during the route starting phase, there is
> forceAssignIds() method in RouteDefinitionHelper class, which will take
> routeId from VerbDefinition and assign it to proper RouteDefinition. And
> then at the end as final result, when all routes are started, you will have
> your route id for your REST DSL route.
> But semantically looking, route id should be assigned to RouteDefinition
> earlier, during lets call it "reading and building RouteDefinitions phase".
>
> Anyway the problem exists when you try to test routes and use AdviceWith.
> I think this is a bug and fix is necessary since AdviceWith currently
> doesn't work for all routes.
>
> What you think about this? Should I open Jira ticket for this?
> Just to mention that I already tried this fix and AdviceWith worked as
> expected.
>
> Kind Regards,
> Nikola Glidzic
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2