Claus Ibsen created CAMEL-27753:
-----------------------------------
Summary: camel-support - PropertyBindingSupport
withPlaceholder(false) and withReference(false) do not apply to values
Key: CAMEL-27753
URL: https://issues.apache.org/jira/browse/CAMEL-27753
Project: Camel
Issue Type: Bug
Components: camel-core
Reporter: Claus Ibsen
Fix For: 4.24.0
{{PropertyBindingSupport.Builder}} has the options {{withPlaceholder}}
("Whether to use Camels property placeholder to resolve placeholders on keys
and values") and {{withReference}} ("Whether reference parameter (syntax starts
with #) is in use"). When both are turned off, a value is still resolved as if
they were on.
*Today*
With
{{build().withPlaceholder(false).withReference(false).withNesting(false).bind(...)}},
these values are not bound as given:
* {{\{\{myKey\}\}}}, {{prefix-\{\{myKey\}\}}} and {{\{\{sys:java.home\}\}}} are
resolved as property placeholders;
* {{#property:myKey}} is resolved from the properties component;
* {{#class:...}} creates the class (and calls the factory method when given);
* {{#bean:name}}, {{#type:...}}, {{#name}}, {{#autowired}} and
{{#valueAs(type):value}} are resolved from the registry or converted.
Only the option names honor {{withPlaceholder(false)}}, and
{{withNesting(false)}} works as documented.
Cause, in {{PropertyBindingSupport}}:
* {{doSetPropertyValue}} calls {{resolveValue}} for every value that is not in
literal mode, whatever {{reference}} is, and after that resolves placeholders
again, gated only by {{literal}};
* {{resolveValue}} -> {{resolveBean}} always resolves placeholders before it
looks at {{#class:}}, {{#type:}}, {{#bean:}} and {{#valueAs}};
* the reflection setter ({{setSimplePropertyViaReflection}}) gets the
{{reflection}} flag as its {{reference}} argument, so {{#name}} is resolved by
reflection even with {{withReference(false)}};
* {{PropertyConfigurerSupport.property}} resolves {{#}} references for
configurer based binding on its own.
*Expected*
* {{withPlaceholder(false)}}: no {{\{\{...\}\}}} resolution in values (keys
already work).
* {{withReference(false)}}: a value starting with {{#}} ({{#property:}},
{{#class:}}, {{#bean:}}, {{#type:}}, {{#name}}, {{#autowired}}, {{#valueAs}})
is bound as given, both for reflection and configurer based binding.
* Defaults (both on) and literal mode ({{withLiteral}}) are unchanged.
*Code changes*
* {{doSetPropertyValue}}: call {{resolveValue}} only when {{reference}} is on;
do the second placeholder pass only when {{placeholder}} is on.
* {{resolveBean}} / {{resolveValue}}: resolve placeholders only when
{{placeholder}} is on (pass the flag down).
* Pass the reference flag (not {{reflection}}) to
{{setSimplePropertyViaReflection}} / {{setPropertyCollectionViaReflection}}.
* Configurer path: skip {{#}} reference resolution in
{{PropertyConfigurerSupport.property}} when references are off (for example
through a thread scoped flag, as for literal option binding).
* Javadoc of {{withLiteral}}: also list {{#autowired}} and
{{#valueAs(type):value}}, which are resolved in literal mode.
*Compatibility*
No test in the repository uses {{withPlaceholder(false)}} or
{{withReference(false)}}. The only in-tree caller that turns them off is
{{SpringCronEndpoint}} (camel-spring), which binds endpoint uri options that
were already resolved when the route was built. Mention the change in the
upgrade guide: code that turns these options off and still expects placeholders
or references in values must turn them on.
*Tests* (camel-core, {{PropertyBindingSupport}} tests)
* For each prefix above: bound as given with the flag off, resolved with the
default flags, for a POJO with reflection and for a target with a generated
configurer.
* Placeholders in keys are still not resolved with {{withPlaceholder(false)}};
nesting is still skipped with {{withNesting(false)}}.
* Literal mode keeps its current behavior.
_Claude Code on behalf of Claus Ibsen_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)