[ 
https://issues.apache.org/jira/browse/CAMEL-27160?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Work on CAMEL-27160 started by Andrea Cosentino.
------------------------------------------------
> camel-core - treat dynamic endpoint option values from the message as literals
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-27160
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27160
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core, camel-support
>            Reporter: Andrea Cosentino
>            Assignee: Andrea Cosentino
>            Priority: Major
>             Fix For: 4.24.0
>
>
> h3. Background
> The dynamic-endpoint EIPs compute their target endpoint URI from the current 
> message at runtime and then ask the {{CamelContext}} for that endpoint. For 
> {{toD}}, {{enrich}}, {{wireTap}} and {{pollEnrich}}, CAMEL-24282 (and its 
> follow-up CAMEL-24414) already made the per-message URI _string_ literal: the 
> recipient URI computed from the message is not passed through 
> property-placeholder resolution, and it is looked up with 
> {{NormalizedUri.newNormalizedUri(uri, false)}}. The recipient-list style EIPs 
> ({{recipientList}}, {{routingSlip}}, {{dynamicRouter}}) deliberately keep 
> resolving property placeholders in their computed URI string, which is 
> documented behaviour.
> h3. Current behaviour
> That change reached the URI _string_ only; it never reached endpoint _option 
> binding_. When the per-message endpoint is created 
> ({{DefaultComponent.createEndpoint}}, then 
> {{DefaultEndpoint.configureProperties}}, then 
> {{DefaultComponent.setProperties}}), its query option _values_ are bound 
> through {{PropertyBindingSupport}}, which runs with reference and placeholder 
> resolution enabled by default ({{reference = true}} and {{placeholder = 
> true}} in {{PropertyBindingSupport.build()}}). As a result, every option 
> value of a per-message recipient is still:
> * resolved as a Camel property placeholder, and
> * when it begins with {{#}}, resolved as a bean or class reference by 
> {{resolveValue}} then {{resolveBean}}: {{#class:}} instantiates the named 
> class (optionally invoking a public constructor or a static factory method 
> with the supplied string arguments), while {{#bean:}} and {{#type:}} resolve 
> a bean from the registry.
> So the behaviour is inconsistent with CAMEL-24282: for {{toD}}, {{enrich}}, 
> {{wireTap}} and {{pollEnrich}} the _path_ of a per-message recipient is 
> literal, but its _options_ are still resolved. For {{recipientList}}, 
> {{routingSlip}} and {{dynamicRouter}} the URI string is resolved (as 
> documented) and the option values are resolved as well.
> h3. Desired behaviour
> When a dynamic endpoint builds its recipient from the message at runtime, the 
> message-derived parts of that recipient -- the path and the option values 
> alike -- are treated as literal text. A property-placeholder token, or a 
> {{#class:}} / {{#bean:}} / {{#type:}} token, that appears in a 
> _runtime-computed_ option value is kept verbatim: it is neither resolved, nor 
> is any class instantiated or bean looked up.
> For {{toD}}, {{enrich}}, {{wireTap}} and {{pollEnrich}} this makes the whole 
> per-message recipient literal (the path already is; now the options are too), 
> finishing what CAMEL-24282 started. For {{recipientList}}, {{routingSlip}} 
> and {{dynamicRouter}} the documented resolution of property placeholders in 
> the computed URI string is preserved; only the bean/class reference 
> resolution of their runtime option values is brought in line.
> Placeholders and references written in the _static_ route template are 
> unaffected: they continue to be resolved once at build time, exactly as today.
> h3. Classes involved
> * {{core/camel-core-processor}}: {{SendDynamicProcessor}} ({{toD}}, 
> {{wireTap}}), {{Enricher}}, {{PollEnricher}}, {{RecipientListProcessor}} and 
> the routing-slip / dynamic-router processors build the per-message recipient 
> and reach endpoint resolution via {{ProcessorHelper}}.
> * {{core/camel-support}}: {{PropertyBindingSupport}} -- the shared option 
> binder whose {{reference}} and {{placeholder}} defaults are {{true}} and 
> whose {{resolveValue}} then {{resolveBean}} reference pass runs independently 
> of those flags; {{DefaultComponent}} ({{createEndpoint}}, {{setProperties}}); 
> {{DefaultEndpoint}} ({{configureProperties}}); {{EndpointHelper}}; and 
> {{NormalizedUri}}, which already carries the 
> normalized-versus-message-derived distinction introduced by CAMEL-24282.
> * {{core/camel-base-engine}}: {{AbstractCamelContext.doGetEndpoint}}, the 
> endpoint lookup/creation seam that receives the normalized URI.
> h3. Code-level change
> Give the per-message recipient an end-to-end "bind literally" contract that 
> extends the CAMEL-24282 treatment from the URI string to the option binding. 
> Add a literal binding mode to {{PropertyBindingSupport}} for message-derived 
> values. A plain flag flip is not sufficient: calling 
> {{withPlaceholder(false).withReference(false)}} does not stop the {{#class:}} 
> / {{#bean:}} / {{#type:}} handling, because {{resolveValue}} then 
> {{resolveBean}} is invoked unconditionally in {{doSetPropertyValue}}, 
> independently of the {{reference}} flag. The literal mode must therefore also 
> skip that reference-resolution pass, so a message-derived value is bound as 
> plain text with no placeholder resolution and no bean/class reference 
> resolution.
> Carry a "this recipient came from the message" signal from the dynamic EIPs 
> through endpoint lookup and creation -- on the {{NormalizedUri}} (as 
> CAMEL-24282 already does for the URI string), or via a dedicated 
> endpoint-creation entry point for the dynamic EIPs -- so that option binding 
> for a per-message endpoint selects the literal mode, while binding for 
> endpoints created from the static route template is unchanged. The documented 
> {{recipientList}} / {{routingSlip}} / {{dynamicRouter}} property-placeholder 
> behaviour for the URI string must be preserved.
> h3. Tests
> Extend 
> {{core/camel-core/src/test/java/org/apache/camel/processor/DynamicEndpointMessagePlaceholderTest.java}},
>  which today covers only the URI _path_, with new option-value cases that 
> follow the same setup (a {{ContextTestSupport}} route, a local in-JVM sink, 
> AssertJ {{assertThat}}, no network):
> * an option value of a per-message recipient that contains a 
> property-placeholder token is kept literal (the option receives the token 
> verbatim);
> * an option value of a per-message recipient that begins with a {{#class:}} / 
> {{#bean:}} / {{#type:}} token is kept literal -- no class is instantiated and 
> no bean is looked up (asserted through a local marker class/bean that must 
> not be created);
> * the same for {{toD}}, {{enrich}}, {{pollEnrich}} and the recipient-list 
> EIPs.
> Keep the existing control asserting that a placeholder written in the 
> _static_ route template is still resolved. Match the existing file's 
> conventions: package-private test methods, AssertJ, and 
> {{assertMockEndpointsSatisfied()}}.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to