davsclaus opened a new pull request, #30580: URL: https://github.com/apache/camel/pull/30580
JIRA: [CAMEL-27361](https://issues.apache.org/jira/browse/CAMEL-27361) ## What was wrong `EndpointUriFactorySupport.buildQueryParameters` picks `?` or `&` for the query with `uri.indexOf('?') != -1`. The check exists on purpose: a context path can already have a `?`, and then the query has to go on with `&`. But an optional property placeholder such as `{{?directoryName}}` in a path parameter also has a `?`, so the query started with `&`: ``` smb:host:445/share/{{?directoryName}}&antInclude=...&password=RAW(...) ``` All the options then ended up in the path and were lost. In the case from the Kamelet catalog, the password was dropped and camel-smb failed with a NullPointerException. ## The fix The new `URISupport.indexOfQuestionMark(String)` returns the first `?` that is not inside `{{ }}`, and it handles nested placeholders. These places now use it, because they all had the same check for the same purpose: - `EndpointUriFactorySupport.buildQueryParameters` (camel-support): the generated endpoint uri factories, used by the YAML DSL `parameters`, Kamelets, etc. - `AbstractCamelCatalog.doAsEndpointUri` (camel-core-catalog), in both branches (all syntax keys given, and some missing). The comment in `EndpointUriFactorySupport` says it copies the catalog's behaviour. - `NamingEndpointDslResolver` (camel-java-io), which builds the URI from an endpoint DSL call such as `file("inbox/{{?subDir}}").noop(true)` in the lightweight Java parser. A real `?` in the context path, outside a placeholder, still makes the query start with `&`, as before. The tests cover this case. Not changed: - `YamlSupport.createEndpointUri` (camel-yaml-dsl-common) has the same `indexOf('?')` check, but it is used to reject `uri: "foo:bar?x=1"` combined with `parameters:`. With `uri: "smb:host/share/{{?dir}}"` plus `parameters:`, it fails with "Uri should not contains query parameters". That is a clear error, not lost options, and it is outside core, so it is left for a follow-up if wanted. - `AbstractEndpointBuilder` (endpoint DSL) resolves placeholders in the path before it checks for `?`, so it does not have this bug. - Other `indexOf('?')` uses in core split an existing URI (scheme lookup, normalisation, rest paths) and do not build a query from parameters. ## Tests - `URISupportTest.testIndexOfQuestionMark` (camel-util): new. 80 tests, all pass. - `EndpointOptionEdgeCasesTest` (camel-core): two new tests. The generated `file` endpoint uri factory with `directoryName=target/data/{{?subDir}}` now gives `file:target/data/{{?subDir}}?noop=true&antInclude=*.txt`, and `getEndpoint` of that URI keeps `noop` and `antInclude`. A path with a real `?` still gets `&`. - `RuntimeCamelCatalogTest.testAsEndpointUriOptionalPlaceholderInPath` (camel-core): new. It covers the catalog for `file` (all syntax keys given) and `language` (a syntax key missing). - `EndpointDslTest.optionalPlaceholderInPath` (camel-java-io): new. - Before the fix, the new camel-core tests fail with `expected: <file:target/data/{{?subDir}}?noop=true&antInclude=*.txt> but was: <file:target/data/{{?subDir}}&noop=true&antInclude=*.txt>`, and in the same way for the catalog and the custom factory. - Also run: - camel-core: `EndpointOptionEdgeCasesTest`, `RuntimeCamelCatalog*`, `CustomEndpointUriFactoryTest`, `*EndpointUri*` and `ToDynamic*`. 88 tests, all pass. - camel-java-io: all 196 tests pass (1 skipped, as before). The changed camel-util, camel-support and camel-core-catalog were installed into a scratch local repository for the camel-core and camel-java-io runs. I did not run the catalog/camel-catalog tests locally. _Claude Code on behalf of davsclaus_ 🤖 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]
