Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ private void doStartRouteDefinitions(List<RouteDefinition> routeDefinitions) thr
// no side-effect from previously used values that Camel may use in its endpoint
// registry and elsewhere
if (bbr != null && !bbr.isEmpty()) {
Map<String, String> beanNameMappings = new HashMap<>();
for (Map.Entry<String, Object> param : params.entrySet()) {
Object value = param.getValue();
if (value instanceof String oldKey) {
Expand All @@ -701,9 +702,18 @@ private void doStartRouteDefinitions(List<RouteDefinition> routeDefinitions) thr
routeDefinition.getId(), oldKey, newKey);
bbrCopy.put(newKey, bbr.remove(oldKey));
param.setValue(newKey);
beanNameMappings.put(oldKey, newKey);
}
}
}
// ensure bean names removed during clash detection are still
// available as template parameters so they can be referenced
// directly in routes via {{beanName}}
for (Map.Entry<String, String> mapping : beanNameMappings.entrySet()) {
if (!params.containsKey(mapping.getKey())) {
params.put(mapping.getKey(), mapping.getValue());
}
}
// the remainder of the local beans must also have their ids made global unique
for (Map.Entry<String, Map<Class<?>, Object>> entry : bbr.entrySet()) {
String oldKey = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,36 @@ public static Processor createBuilderProcessorThree(String prefix) {
return answer;
}

@Test
public void testLocalBeanWithParamValueClash() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
routeTemplate("myTemplate")
.templateParameter("foo")
.templateParameter("scheme")
.templateBean("counter").typeClass(AtomicInteger.class).end()
.from("direct:{{foo}}")
.to("bean:{{counter}}?method=getAndIncrement");
}
});

context.start();

TemplatedRouteBuilder.builder(context, "myTemplate")
.parameter("foo", "one")
.parameter("scheme", "counter")
.routeId("myRoute")
.add();

assertEquals(1, context.getRoutes().size());

Object out = template.requestBody("direct:one", "World");
assertEquals(0, out);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to ease readability, it would be nice to add a message for assertion explaining why it expects 0

out = template.requestBody("direct:one", "World");
assertEquals(1, out);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to ease readability, it would be nice to add a message for assertion explaining why it expects 1


context.stop();
}

}