[ 
https://issues.apache.org/jira/browse/CAMEL-25068?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18123580#comment-18123580
 ] 

shashank commented on CAMEL-25068:
----------------------------------

I went through both items on current main (374c04877418) with a JUnit test 
each. Both reproduce, and both need a decision, so no PR yet; options and a 
recommendation below.

*1. A bean given to {{TemplatedRouteBuilder}} with the same name as a 
{{templateBean}}* - reproduced, and the precedence depends on how the caller 
binds the bean:
* {{TemplatedRouteBuilder...bean("greeting", mine)}}: the template bean wins;
* {{TemplatedRouteDefinition.bean("greeting", ...)}} 
({{addRouteFromTemplatedRoute}}): the template bean wins;
* {{TemplatedRouteBuilder...configure(rtc -> rtc.bind("greeting", mine))}}: the 
caller's bean wins.
The caller's beans are bound before {{DefaultModel.doAddRouteFromTemplate}}, 
which then binds the template beans into the same local registry and replaces 
them; configurers run later, when the route is created.
Options:
* (a) the caller's bean wins: {{addTemplateBeans}} skips a template bean whose 
name the caller already bound. Consistent with the configurer, with CAMEL-25048 
item 6 (the builder's configurer runs after the template's), with parameters 
overriding template defaults, and with replacing a bean by a mock in tests. 
Kamelets are not affected (they only pass parameters). Needs an upgrade note 
and a sentence in route-template.adoc;
* (b) the template bean wins: document it, and bind the template beans after 
the configurers so the configurer path agrees;
* (c) fail on a clash.
Recommendation: (a).

*2. A route id from a template that is the same as an existing route* - 
reproduced: with a route {{existing}} ({{from("direct:existing")}}), 
{{TemplatedRouteBuilder...routeId("existing")...add()}} does not throw, and 
afterwards the only route {{existing}} consumes from the template's endpoint; 
the original route is gone. Kamelets go through the same code, so two 
{{kamelet:tmpl/myRoute?...}} endpoints with the same explicit route id and 
different parameters replace each other's route as well.
Options:
* (a) fail with {{FailedToCreateRouteFromTemplateException}} when a route with 
that id already exists, for routes from templates (and Kamelets) - consistent 
with the existing "Duplicate id detected" check for node ids. Needs an upgrade 
note. Route reload with the default {{removeAllRoutes=true}} removes all routes 
first and is not affected; with {{removeAllRoutes=false}} a reloaded 
{{templatedRoute}} would need its old route removed first (to be covered by a 
test);
* (b) log a WARN and keep replacing;
* (c) keep and document.
Recommendation: (a).

Both are small changes once decided; I'll send a PR for each referencing this 
ticket.

_Claude Code on behalf of allthingssecurity_


> camel-core - Route templates: follow-ups from the deep review
> -------------------------------------------------------------
>
>                 Key: CAMEL-25068
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25068
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Priority: Minor
>
> Follow-ups found in the review of CAMEL-25048 
> (https://github.com/apache/camel/pull/26929), not changed there:
> # A bean given to TemplatedRouteBuilder with the same name as a templateBean 
> is overridden by the template bean. Which one should win needs a decision 
> (and documentation).
> # A route id from a template that is the same as an existing route silently 
> replaces that route (as adding a route with an existing id does). Consider 
> failing or warning for templated routes.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to