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 2022/12/12 12:13:15 UTC

BUG - missing configuration placeholder possibility for id in REST DSL

Hello Camel crew,

I think there is a bug when using placeholder for route id in REST DSL route. I am using Camel 3.18.4, but same problem exists in previous versions as well.

I want my REST route to have my custom route id loaded from configuration by using configuration placeholder, like this:

rest()
                .post("{{endpoint.uri}}")                            <- loaded nice
                .id("{{endpoint.id}}")                                   <- NOT loaded
                .type(Claim.class)
                .consumes("application/json")
                .bindingMode(RestBindingMode.json)
                .to("direct:some_channel")

Endpoint uri placeholder will be loaded good, but placeholder for id will not be loaded and my route id will remain as "{{endpoint.id}}".

I think mistake and fix solution for this stands in class RouteDefinitionHelper, in method forceAssignIds():

If you check the provided image, I think that line 154 for resolving REST route id should have the same placeholder resolving logic as it is in line 142.

Should I create JIRA ticket for this or will you do it? It is probably better if you do it, but please provide us link of JIRA ticket in response so we can track the progress.

Thanks in advance!
Kind Regards,
Nikola Glidzic




Re: BUG - missing configuration placeholder possibility for id in REST DSL

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

Ah okay, yeah its not very common to use placeholders for ids and therefore
it's not resolved there before.
Yes you are welcome to create a JIRA and send a PR for this improvement

On Mon, Dec 12, 2022 at 1:28 PM Nikola Glidzic <ni...@ikor.one>
wrote:

> Sorry guys, I didn't know image can't be sent. Combine this email with
> previous one. Here is the relevant part of code of method forceAssignIds(),
> mentioned lines are marked with arrows:
>
> public static void forceAssignIds(CamelContext context,
> List<RouteDefinition> routes) throws Exception {
>         ExtendedCamelContext ecc =
> context.adapt(ExtendedCamelContext.class);
>
>         // handle custom assigned id's first, and then afterwards assign
> auto
>         // generated ids
>         Set<String> customIds = new HashSet<>();
>
>         for (final RouteDefinition route : routes) {
>             // if there was a custom id assigned, then make sure to support
>             // property placeholders
>             if (route.hasCustomIdAssigned()) {
>                 final String originalId = route.getId();
>                 final String id =
> context.resolvePropertyPlaceholders(originalId);
>
>   <- line 142
>                 // only set id if its changed, such as we did property
>                 // placeholder
>                 if (!originalId.equals(id)) {
>                     route.setId(id);
>                 }
>                 customIds.add(id);
>             } else {
>                 RestDefinition rest = route.getRestDefinition();
>                 if (rest != null && route.isRest()) {
>                     VerbDefinition verb = findVerbDefinition(rest,
> route.getInput().getEndpointUri());
>                     if (verb != null) {
>                         String id = verb.getId();
>
>
>  <- line 154
>                         if (verb.hasCustomIdAssigned() &&
> ObjectHelper.isNotEmpty(id) && !customIds.contains(id)) {
>                             route.setId(id);
>                             customIds.add(id);
>                         }
>                     }
>                 }
>             }
>         }
>
>
> From: Nikola Glidzic
> Sent: Monday, December 12, 2022 1:13 PM
> To: users@camel.apache.org
> Subject: BUG - missing configuration placeholder possibility for id in
> REST DSL
>
> Hello Camel crew,
>
> I think there is a bug when using placeholder for route id in REST DSL
> route. I am using Camel 3.18.4, but same problem exists in previous
> versions as well.
>
> I want my REST route to have my custom route id loaded from configuration
> by using configuration placeholder, like this:
>
> rest()
>                 .post("{{endpoint.uri}}")                            <-
> loaded nice
>                 .id("{{endpoint.id}}")
>  <- NOT loaded
>                 .type(Claim.class)
>                 .consumes("application/json")
>                 .bindingMode(RestBindingMode.json)
>                 .to("direct:some_channel")
>
> Endpoint uri placeholder will be loaded good, but placeholder for id will
> not be loaded and my route id will remain as "{{endpoint.id}}".
>
> I think mistake and fix solution for this stands in class
> RouteDefinitionHelper, in method forceAssignIds():
>
> If you check the provided image, I think that line 154 for resolving REST
> route id should have the same placeholder resolving logic as it is in line
> 142.
>
> Should I create JIRA ticket for this or will you do it? It is probably
> better if you do it, but please provide us link of JIRA ticket in response
> so we can track the progress.
>
> Thanks in advance!
> Kind Regards,
> Nikola Glidzic
>
>
>
>

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

RE: BUG - missing configuration placeholder possibility for id in REST DSL

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

Thank you for fixing the reported problem. We will track this JIRA and PR.
But I see the title of your JIRA ticket is related to URI placeholder, but I have reported problem with .id() placeholder.
So id placeholder should be fixed. If anything is left unclear, be free to ask me, so we can make it more clear.

Kind Regards,
Nikola Glidzic
From: Nikola Glidzic
Sent: Monday, December 12, 2022 1:24 PM
To: users@camel.apache.org
Subject: RE: BUG - missing configuration placeholder possibility for id in REST DSL

Sorry guys, I didn't know image can't be sent. Combine this email with previous one. Here is the relevant part of code of method forceAssignIds(), mentioned lines are marked with arrows:

public static void forceAssignIds(CamelContext context, List<RouteDefinition> routes) throws Exception {
        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);

        // handle custom assigned id's first, and then afterwards assign auto
        // generated ids
        Set<String> customIds = new HashSet<>();

        for (final RouteDefinition route : routes) {
            // if there was a custom id assigned, then make sure to support
            // property placeholders
            if (route.hasCustomIdAssigned()) {
                final String originalId = route.getId();
                final String id = context.resolvePropertyPlaceholders(originalId);                                                                                                          <- line 142
                // only set id if its changed, such as we did property
                // placeholder
                if (!originalId.equals(id)) {
                    route.setId(id);
                }
                customIds.add(id);
            } else {
                RestDefinition rest = route.getRestDefinition();
                if (rest != null && route.isRest()) {
                    VerbDefinition verb = findVerbDefinition(rest, route.getInput().getEndpointUri());
                    if (verb != null) {
                        String id = verb.getId();                                                                                                                                                                                   <- line 154
                        if (verb.hasCustomIdAssigned() && ObjectHelper.isNotEmpty(id) && !customIds.contains(id)) {
                            route.setId(id);
                            customIds.add(id);
                        }
                    }
                }
            }
        }


From: Nikola Glidzic
Sent: Monday, December 12, 2022 1:13 PM
To: users@camel.apache.org<ma...@camel.apache.org>
Subject: BUG - missing configuration placeholder possibility for id in REST DSL

Hello Camel crew,

I think there is a bug when using placeholder for route id in REST DSL route. I am using Camel 3.18.4, but same problem exists in previous versions as well.

I want my REST route to have my custom route id loaded from configuration by using configuration placeholder, like this:

rest()
                .post("{{endpoint.uri}}")                            <- loaded nice
                .id("{{endpoint.id}}")                                   <- NOT loaded
                .type(Claim.class)
                .consumes("application/json")
                .bindingMode(RestBindingMode.json)
                .to("direct:some_channel")

Endpoint uri placeholder will be loaded good, but placeholder for id will not be loaded and my route id will remain as "{{endpoint.id}}".

I think mistake and fix solution for this stands in class RouteDefinitionHelper, in method forceAssignIds():

If you check the provided image, I think that line 154 for resolving REST route id should have the same placeholder resolving logic as it is in line 142.

Should I create JIRA ticket for this or will you do it? It is probably better if you do it, but please provide us link of JIRA ticket in response so we can track the progress.

Thanks in advance!
Kind Regards,
Nikola Glidzic




Re: BUG - missing configuration placeholder possibility for id in REST DSL

Posted by Babak Vahdat <ba...@swissonline.ch.INVALID>.
Hi

I ran into a similar but not the same issue I’m working on to fix and PR soon.

https://issues.apache.org/jira/browse/CAMEL-18809 <https://issues.apache.org/jira/browse/CAMEL-18809>

—
Babak

> On 12 Dec 2022, at 13:24, Nikola Glidzic <ni...@ikor.one> wrote:
> 
> Sorry guys, I didn't know image can't be sent. Combine this email with previous one. Here is the relevant part of code of method forceAssignIds(), mentioned lines are marked with arrows:
> 
> public static void forceAssignIds(CamelContext context, List<RouteDefinition> routes) throws Exception {
>        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
> 
>        // handle custom assigned id's first, and then afterwards assign auto
>        // generated ids
>        Set<String> customIds = new HashSet<>();
> 
>        for (final RouteDefinition route : routes) {
>            // if there was a custom id assigned, then make sure to support
>            // property placeholders
>            if (route.hasCustomIdAssigned()) {
>                final String originalId = route.getId();
>                final String id = context.resolvePropertyPlaceholders(originalId);                                                                                                          <- line 142
>                // only set id if its changed, such as we did property
>                // placeholder
>                if (!originalId.equals(id)) {
>                    route.setId(id);
>                }
>                customIds.add(id);
>            } else {
>                RestDefinition rest = route.getRestDefinition();
>                if (rest != null && route.isRest()) {
>                    VerbDefinition verb = findVerbDefinition(rest, route.getInput().getEndpointUri());
>                    if (verb != null) {
>                        String id = verb.getId();                                                                                                                                                                                   <- line 154
>                        if (verb.hasCustomIdAssigned() && ObjectHelper.isNotEmpty(id) && !customIds.contains(id)) {
>                            route.setId(id);
>                            customIds.add(id);
>                        }
>                    }
>                }
>            }
>        }
> 
> 
> From: Nikola Glidzic
> Sent: Monday, December 12, 2022 1:13 PM
> To: users@camel.apache.org
> Subject: BUG - missing configuration placeholder possibility for id in REST DSL
> 
> Hello Camel crew,
> 
> I think there is a bug when using placeholder for route id in REST DSL route. I am using Camel 3.18.4, but same problem exists in previous versions as well.
> 
> I want my REST route to have my custom route id loaded from configuration by using configuration placeholder, like this:
> 
> rest()
>                .post("{{endpoint.uri}}")                            <- loaded nice
>                .id("{{endpoint.id}}")                                   <- NOT loaded
>                .type(Claim.class)
>                .consumes("application/json")
>                .bindingMode(RestBindingMode.json)
>                .to("direct:some_channel")
> 
> Endpoint uri placeholder will be loaded good, but placeholder for id will not be loaded and my route id will remain as "{{endpoint.id}}".
> 
> I think mistake and fix solution for this stands in class RouteDefinitionHelper, in method forceAssignIds():
> 
> If you check the provided image, I think that line 154 for resolving REST route id should have the same placeholder resolving logic as it is in line 142.
> 
> Should I create JIRA ticket for this or will you do it? It is probably better if you do it, but please provide us link of JIRA ticket in response so we can track the progress.
> 
> Thanks in advance!
> Kind Regards,
> Nikola Glidzic
> 
> 
> 


RE: BUG - missing configuration placeholder possibility for id in REST DSL

Posted by Nikola Glidzic <ni...@ikor.one>.
Sorry guys, I didn't know image can't be sent. Combine this email with previous one. Here is the relevant part of code of method forceAssignIds(), mentioned lines are marked with arrows:

public static void forceAssignIds(CamelContext context, List<RouteDefinition> routes) throws Exception {
        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);

        // handle custom assigned id's first, and then afterwards assign auto
        // generated ids
        Set<String> customIds = new HashSet<>();

        for (final RouteDefinition route : routes) {
            // if there was a custom id assigned, then make sure to support
            // property placeholders
            if (route.hasCustomIdAssigned()) {
                final String originalId = route.getId();
                final String id = context.resolvePropertyPlaceholders(originalId);                                                                                                          <- line 142
                // only set id if its changed, such as we did property
                // placeholder
                if (!originalId.equals(id)) {
                    route.setId(id);
                }
                customIds.add(id);
            } else {
                RestDefinition rest = route.getRestDefinition();
                if (rest != null && route.isRest()) {
                    VerbDefinition verb = findVerbDefinition(rest, route.getInput().getEndpointUri());
                    if (verb != null) {
                        String id = verb.getId();                                                                                                                                                                                   <- line 154
                        if (verb.hasCustomIdAssigned() && ObjectHelper.isNotEmpty(id) && !customIds.contains(id)) {
                            route.setId(id);
                            customIds.add(id);
                        }
                    }
                }
            }
        }


From: Nikola Glidzic
Sent: Monday, December 12, 2022 1:13 PM
To: users@camel.apache.org
Subject: BUG - missing configuration placeholder possibility for id in REST DSL

Hello Camel crew,

I think there is a bug when using placeholder for route id in REST DSL route. I am using Camel 3.18.4, but same problem exists in previous versions as well.

I want my REST route to have my custom route id loaded from configuration by using configuration placeholder, like this:

rest()
                .post("{{endpoint.uri}}")                            <- loaded nice
                .id("{{endpoint.id}}")                                   <- NOT loaded
                .type(Claim.class)
                .consumes("application/json")
                .bindingMode(RestBindingMode.json)
                .to("direct:some_channel")

Endpoint uri placeholder will be loaded good, but placeholder for id will not be loaded and my route id will remain as "{{endpoint.id}}".

I think mistake and fix solution for this stands in class RouteDefinitionHelper, in method forceAssignIds():

If you check the provided image, I think that line 154 for resolving REST route id should have the same placeholder resolving logic as it is in line 142.

Should I create JIRA ticket for this or will you do it? It is probably better if you do it, but please provide us link of JIRA ticket in response so we can track the progress.

Thanks in advance!
Kind Regards,
Nikola Glidzic