Claus Ibsen created CAMEL-25048:
-----------------------------------
Summary: camel-core - Route templates: fix bugs found in a deep
review
Key: CAMEL-25048
URL: https://issues.apache.org/jira/browse/CAMEL-25048
Project: Camel
Issue Type: Bug
Components: camel-core
Reporter: Claus Ibsen
A deep review of route templates (RouteTemplateDefinition,
TemplatedRouteDefinition, the local beans and the creation of routes from
templates) found the bugs below. Each one was reproduced against
4.23.0-SNAPSHOT and has a test that fails without the fix.
# *A local bean referred to by a parameter is only renamed for one of the
parameter's keys.* Every parameter is stored as both camelCase and kebab-case
(beanRef and bean-ref), and when its value is the name of a local bean (which
is renamed to be unique), only the first key was renamed; the bean was then
removed from the list, so the other key kept the old name. Depending on HashMap
order, to("bean:{{beanRef}}") failed with NoSuchBeanException. All local beans
are now renamed in one pass and every parameter referring to one is updated.
# *The destroy method of such a local bean is never called.* The renaming
removed the bean from the local bean repository, so it was not found when the
route was removed.
# *A local bean from a supplier is not a singleton.* templateBean(name, type,
rtc -> ...) and the templated route bean(...) with a supplier called the
supplier on every lookup, so two references got two instances. They are now
cached, as documented; bindAsPrototype (which failed with
UnsupportedOperationException) binds the supplier without caching.
# *TemplatedRouteDefinition.bean(name, language, script) sets the language as
the type*, so it failed with ClassNotFoundException (the same methods on
RouteTemplateDefinition are correct).
# *A local bean factory does not see a parameter given in the other key style
or from an environment variable.* rtc.getProperty("myRegion") was null when the
parameter was given as my-region, and the default when given as an environment
variable, while the route used the given value.
# *The configurer of TemplatedRouteBuilder is dropped when the template also
has a configurer.* Both are now called, the template first.
# *Node ids of a route from a template are compared unprefixed with other
routes.* A hardcoded node id in a template clashed with the same id in a
regular route (a false duplicate id, depending on the order routes are added),
while two template routes with the same prefixId were not reported although
their ids are the same at runtime.
# *A #class local bean is bound as Object*, so it cannot be looked up by its
type. It is now bound with its class (unless it is created by a factory method).
*Not changed*
* A bean given to TemplatedRouteBuilder with the same name as a templateBean is
overridden by the template bean; the precedence needs a decision.
* A route id from a template that is the same as an existing route replaces
that route; that is how adding a route with an existing id works.
_Claude Code on behalf of Claus Ibsen_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)