Search code examples
javaspring-bootapache-camelmigrationapache-camel-3

Why property doesn't get evaluated correctly in Camel 3.7.3?


I have a route

String XYZ = "xyz";

from(URL_A)
  .bean(PropertiesSetterBean.class)
  .to("${property." + XYZ + "}")

where PropertiesSetterBean is:

@Component
class PropertiesSetterBean {
  public void copyProperties(@Headers Map<String, Object> headers, @ExchangeProperties Map<String, Object> properties) {
    properties.put("xyz", "direct:test")
  }
}

The error I get:

Failed to create route route1 at: >>> DynamicTo[${property.xyz}] <<< in route: Route(route1)[From[seda:inEvents?concurrentCon... because of Property with key [property.xyz] not found in properties from text: ${property.xyz}

It looks like bean doesn't get executed.

I use camel:3.7.3, spring-boot:2.4.3, java:11

Steps I did:

  • I read the migration guide
  • Looked at available code snippets on GitHub
  • Search StackOverflow
  • Talked to colleagues

I looked into a similar issue.

And still, I cannot triage the issue.

What am I doing wrong?

UPDATE 1

I added the processor:

.process(exchange -> {
  System.out.println("This is my property: " + exchange.getProperty("xyz"));
})

It works. In the meantime, I still cannot retrieve this property with simple DSL in Camel.


Solution

  • After several hours of search with no result, I bumped into an old post.

    To access the property, I will need to use "${exchangeProperty." + XYZ + "}".

    Note:

    • It worked with Camel 2.X.X, so beware of this change.
    • If you have a collision between Spring and Camel placeholders, use $simple instead of $.
    • In Camel 3.X.X you will need to check where your properties located and repoint them to exchangeProperty