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

   ## Summary
   
   Fix inconsistent URL-encoding of kamelet parameters when using `toD` vs `to` 
(CAMEL-24747).
   
   ## Root Cause
   
   When `SendDynamicProcessor` (used by `toD`) resolves a dynamic endpoint, 
`prepareRecipient()` wraps the URI in a `NormalizedUri` — which stores the 
URL-normalized (encoded) form. This `NormalizedUri` is then passed through 
`DefaultCamelContextExtension.getEndpoint(NormalizedEndpointUri)` to 
`doGetEndpoint()` with `normalized=true`.
   
   In `doGetEndpoint`, when `normalized=true`, `rawUri` is set to the 
already-encoded `uri` string before the component check. The line:
   
   ```java
   answer = component.createEndpoint(
           component.useRawUri() ? rawUri : uri,
           parameters);
   ```
   
   …therefore passes the **encoded** URI to `KameletComponent` even though it 
declares `useRawUri()=true`. Parameter values like 
`http://example.com?key=abc%+def` arrive as 
`http%3A%2F%2Fexample.com%3Fkey%3Dabc%25%2Bdef`.
   
   The static `to` DSL is unaffected because it calls `doGetEndpoint(uri, null, 
false, false)` (i.e. `normalized=false`), so `rawUri` is captured **before** 
normalization.
   
   ## Fix
   
   Extended `NormalizedUri` with a `rawUri` field that preserves the original 
un-normalized URI alongside the normalized form used for endpoint cache keys. 
`DefaultCamelContextExtension.getEndpoint(NormalizedEndpointUri)` now extracts 
this raw URI and passes it to a new `doGetEndpoint` overload, ensuring 
`component.useRawUri() ? rawUri : uri` receives the correct un-encoded string.
   
   Files changed:
   - `core/camel-support/…/NormalizedUri.java` — add `rawUri` field + 
`getRawUri()` getter
   - `core/camel-base-engine/…/AbstractCamelContext.java` — new `doGetEndpoint` 
overload with explicit `rawUri` parameter
   - `core/camel-base-engine/…/DefaultCamelContextExtension.java` — pass raw 
URI from `NormalizedUri` through the extension methods
   - `components/camel-kamelet/…/KameletToDUrlEncodingTest.java` — regression 
test
   
   ## Test
   
   New test `KameletToDUrlEncodingTest.toDPreservesSpecialCharsLikeTo` verifies 
that a kamelet parameter containing `%`, `+`, `?`, and `=` (e.g. 
`http://example.com?key=abc%+def`) is received by the kamelet body expression 
**unchanged** when invoked via `toD`, matching the result of the static `to` 
DSL.
   
   Existing test `KameletGlobalPropertiesTest.urlEncodingIsRespected` (which 
verifies the CAMEL-22511 fix — raw mode for secret values — is preserved) 
continues to pass.
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
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