davsclaus opened a new pull request, #31402:
URL: https://github.com/apache/camel/pull/31402

   Fixes [CAMEL-28128](https://issues.apache.org/jira/browse/CAMEL-28128)
   
   ### Problem
   
   With a dynamic uri (`toD`, `enrich` with an expression, `wireTap` with a 
dynamic uri), the query of a `sql` endpoint is part of the uri path, and `toD` 
computes the whole uri before the endpoint is resolved. So the expression 
parameters of the query (`:#${...}`, `:#$simple{...}`, `:#in:${...}`) were 
resolved by `toD` itself: their values became part of the query text instead of 
being bound by the producer. For example `toD("sql:select * from projects where 
project = :#${header.p}")` with `p=AMQ` failed with `Cannot find key [AMQ]`, 
because the producer saw `:#AMQ` and looked up a parameter named `AMQ`. The 
same query works with a static `to`.
   
   The producer also parsed the computed query for parameters once more, 
including expression parameters that only appear in the text that `toD` 
computed from the message.
   
   ### Change
   
   - New `SqlSendDynamicAware` (`@SendDynamic("sql")`, generated 
`META-INF/services/org/apache/camel/send-dynamic/sql`), in the same way as the 
file components:
     - the expression parameters written in the uri of the route keep their 
text, and the producer binds them for each message, as with `to`. The rest of 
the uri is computed from the message as before;
     - an expression parameter that is not in the uri as written in the route, 
and only comes up in the computed uri (also in its percent-encoded form, or 
with a `placeholder` option in the computed uri), fails with a 
`ResolveEndpointFailedException`;
     - named parameters (`:#name`) in the computed text keep working 
(CAMEL-14299, `SqlProducerToDTest` is unchanged).
   - When the uri of the route has expression parameters, the aware computes 
the uri again with these parameters left out, so the other functions of that 
uri are evaluated a second time for such a message. With 
`allowOptimisedComponents=false` the aware is not used, and the uri is computed 
as before.
   - Docs: a new "Using expression parameters with toD" section in 
`sql-component.adoc` (and the catalog copy).
   - Upgrade guide: a note in `camel-4x-upgrade-guide-4_25.adoc`.
   
   ### Tests
   
   - `SqlProducerToDBindParameterTest`: `:#${header.p}` and 
`:#$simple{header.p}` in a `toD` (next to a computed table name) return the 
matching row, and a value that is not a project name returns none.
   - `SqlProducerToDInParameterTest`: `:#in:${header.ids}` in a `toD` binds the 
list.
   - `SqlProducerToDExpressionParameterFromMessageTest`: a `toD` that puts a 
header into the query: a `:#name` parameter in it is bound; a `:#${...}`, 
`:#$simple{...}`, `:#in:${...}` or percent-encoded expression parameter in it 
fails with `ResolveEndpointFailedException`, also next to a parameter written 
in the route.
   - All the new tests fail without the change; the existing camel-sql tests 
pass.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to