This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 67e6157547dc CAMEL-21787: camel-kamelet - opt-in advancedOptions
forwards extra URI parameters to the wrapped endpoint (#27832)
67e6157547dc is described below
commit 67e6157547dc2ac3b462e4edc03606755e28ab53
Author: Ramu <[email protected]>
AuthorDate: Thu Oct 15 13:05:57 2026 +0530
CAMEL-21787: camel-kamelet - opt-in advancedOptions forwards extra URI
parameters to the wrapped endpoint (#27832)
AI-assisted: Grok and Cursor on behalf of ramu11; follow-up by Claude Code
on behalf of davsclaus.
Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---
.../apache/camel/catalog/components/kamelet.json | 12 +-
.../camel/catalog/docs/kamelet-component.adoc | 67 +-
.../kamelet/KameletComponentConfigurer.java | 6 +
.../kamelet/KameletEndpointConfigurer.java | 6 +
.../kamelet/KameletEndpointUriFactory.java | 3 +-
.../apache/camel/component/kamelet/kamelet.json | 12 +-
.../src/main/docs/kamelet-component.adoc | 67 +-
.../apache/camel/component/kamelet/Kamelet.java | 316 ++++-
.../camel/component/kamelet/KameletComponent.java | 49 +
.../camel/component/kamelet/KameletEndpoint.java | 16 +
.../kamelet/KameletAdvancedOptionsTest.java | 1473 ++++++++++++++++++++
.../dsl/KameletComponentBuilderFactory.java | 21 +
.../dsl/KameletEndpointBuilderFactory.java | 108 ++
13 files changed, 2139 insertions(+), 17 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kamelet.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kamelet.json
index 753ec91c2cd4..14d0fbcb6a6c 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kamelet.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/kamelet.json
@@ -31,9 +31,10 @@
"block": { "index": 4, "kind": "property", "displayName": "Block",
"group": "producer", "label": "producer", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": true, "description": "If sending a message to a kamelet
endpoint which has no active consumer, then we can tell the producer to block
and wait for the consumer to become active." },
"lazyStartProducer": { "index": 5, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the producer should be started lazy (on the first message). By
starting lazy you can use this to allow CamelContext and routes to startup in
situations where a producer may otherwise fail [...]
"timeout": { "index": 6, "kind": "property", "displayName": "Timeout",
"group": "producer", "label": "producer", "required": false, "type": "integer",
"javaType": "long", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 30000, "description": "The timeout value to use if block is
enabled." },
- "autowiredEnabled": { "index": 7, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
- "noErrorHandler": { "index": 8, "kind": "property", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs r [...]
- "routeTemplateLoaderListener": { "index": 9, "kind": "property",
"displayName": "Route Template Loader Listener", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.RouteTemplateLoaderListener", "deprecated": false,
"autowired": true, "secret": false, "description": "To plugin a custom listener
for when the Kamelet component is loading Kamelets from external resources." }
+ "advancedOptions": { "index": 7, "kind": "property", "displayName":
"Advanced Options", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to forward extra URI parameters to the endpoint wrapped by the
Kamelet. When enabled, parameters that are not Kamelet template properties or
reserved Kamelet options are appended to the wrappe [...]
+ "autowiredEnabled": { "index": 8, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "noErrorHandler": { "index": 9, "kind": "property", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs r [...]
+ "routeTemplateLoaderListener": { "index": 10, "kind": "property",
"displayName": "Route Template Loader Listener", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.RouteTemplateLoaderListener", "deprecated": false,
"autowired": true, "secret": false, "description": "To plugin a custom listener
for when the Kamelet component is loading Kamelets from external resources." }
},
"properties": {
"templateId": { "index": 0, "kind": "path", "displayName": "Template Id",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired":
false, "secret": false, "description": "The Route Template ID" },
@@ -45,7 +46,8 @@
"failIfNoConsumers": { "index": 6, "kind": "parameter", "displayName":
"Fail If No Consumers", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": true, "description": "Whether the producer should fail by
throwing an exception, when sending to a kamelet endpoint with no active
consumers." },
"lazyStartProducer": { "index": 7, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
"timeout": { "index": 8, "kind": "parameter", "displayName": "Timeout",
"group": "producer (advanced)", "label": "producer,advanced", "required":
false, "type": "integer", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 30000, "description": "The timeout
value to use if block is enabled." },
- "location": { "index": 9, "kind": "parameter", "displayName": "Location",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "Location of the Kamelet to
use which can be specified as a resource from file system, classpath etc. The
location cannot use wildcards, and must refer to a file including extension,
for example file:\/etc\/ [...]
- "noErrorHandler": { "index": 10, "kind": "parameter", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs [...]
+ "advancedOptions": { "index": 9, "kind": "parameter", "displayName":
"Advanced Options", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to forward extra URI parameters to the endpoint wrapped by the
Kamelet. When enabled, parameters that are not Kamelet template properties or
reserved Kamelet options are appended to the wrapp [...]
+ "location": { "index": 10, "kind": "parameter", "displayName": "Location",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "Location of the Kamelet to
use which can be specified as a resource from file system, classpath etc. The
location cannot use wildcards, and must refer to a file including extension,
for example file:\/etc\ [...]
+ "noErrorHandler": { "index": 11, "kind": "parameter", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
index dbf297fb88f6..2fd776e2bb9b 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
@@ -163,6 +163,72 @@ The usage of this Kamelet into a Camel route is going to
be the same as any othe
WARNING: beware of any potential circular reference you may introduce when
using chain of Kamelets, in which case, the runtime will likely be idle
consuming a high amount of resources.
+=== Advanced component endpoint options
+
+Kamelets expose a defined set of parameters, but the underlying Camel
component may support additional endpoint options.
+You can forward those options by enabling `advancedOptions` (disabled by
default).
+
+When enabled, extra URI parameters that are not Kamelet template properties
and not reserved Kamelet options
+(`routeId`, `templateId`, `location`, `advancedOptions`, and the other kamelet
endpoint options) are appended to the
+endpoint wrapped by the Kamelet.
+
+Enable the feature on the component, or on a single endpoint. The endpoint
setting overrides the component setting.
+
+[source,properties]
+----
+camel.component.kamelet.advanced-options=true
+----
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("kamelet:aws-s3-source?advancedOptions=true&bucketNameOrArn=x&maxConnections=100")
+ .to("log:info");
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: kamelet:aws-s3-source
+ parameters:
+ advancedOptions: true
+ bucketNameOrArn: x
+ maxConnections: 100
+ steps:
+ - to:
+ uri: log:info
+----
+====
+
+In this example, `bucketNameOrArn` is a template property of the Kamelet and
stays a template parameter.
+`maxConnections=100` is forwarded to the wrapped `aws2-s3` endpoint. If that
endpoint URI already contains the same option,
+the advanced option overrides its existing value.
+
+Source Kamelets forward extra options to their input endpoint. Sink and action
Kamelets forward extra options to the
+Kamelet's main `to()` endpoint.
+
+The options are applied only when the Kamelet has exactly one eligible
top-level, statically-defined `to()` destination.
+Kamelet endpoints and auxiliary destinations such as `wireTap()` are excluded.
Nested branch destinations, such as those
+inside `choice()` or `doTry()`, are not considered eligible main destinations.
+
+If an action Kamelet has no wrapped endpoint, or the Kamelet contains multiple
eligible top-level destinations, or it
+uses a dynamic destination such as `toD()`, `enrich()`, or `pollEnrich()`,
startup fails with an explanatory exception
+when advanced options are supplied. In these cases, configure the options
directly on the intended endpoint URI.
+
+Property placeholders and RAW expressions in endpoint URIs are preserved when
advanced options are applied. For example,
+`+kafka:{{topic}}+` or `+aws2-s3:{{bucket}}?secretKey=RAW({{secret}})+` remain
intact.
+
+The advanced options are forwarded as they are written in the Kamelet URI.
Percent-encoded values, `RAW(...)` values
+and repeated parameters reach the wrapped endpoint the same way as when the
options are set on that endpoint directly.
+
+When `advancedOptions` is disabled or omitted, the Kamelet retains its
existing configuration behavior.
+
== Examples
_Kamelets_ can be used as if they were standard Camel components.
@@ -219,7 +285,6 @@ YAML::
----
====
-
Behind the scenes, the *Kamelet* component does the following things:
1. it instantiates a route out of the Route Template identified by the given
`templateId` path parameter (in this case `setMyBody`)
diff --git
a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java
b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java
index f0c427493a1b..14585cfc40d8 100644
---
a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java
+++
b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java
@@ -23,6 +23,8 @@ public class KameletComponentConfigurer extends
PropertyConfigurerSupport implem
public boolean configure(CamelContext camelContext, Object obj, String
name, Object value, boolean ignoreCase) {
KameletComponent target = (KameletComponent) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
+ case "advancedoptions":
+ case "advancedOptions":
target.setAdvancedOptions(property(camelContext, boolean.class, value)); return
true;
case "autowiredenabled":
case "autowiredEnabled":
target.setAutowiredEnabled(property(camelContext, boolean.class, value));
return true;
case "block": target.setBlock(property(camelContext, boolean.class,
value)); return true;
@@ -52,6 +54,8 @@ public class KameletComponentConfigurer extends
PropertyConfigurerSupport implem
@Override
public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
+ case "advancedoptions":
+ case "advancedOptions": return boolean.class;
case "autowiredenabled":
case "autowiredEnabled": return boolean.class;
case "block": return boolean.class;
@@ -77,6 +81,8 @@ public class KameletComponentConfigurer extends
PropertyConfigurerSupport implem
public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
KameletComponent target = (KameletComponent) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
+ case "advancedoptions":
+ case "advancedOptions": return target.isAdvancedOptions();
case "autowiredenabled":
case "autowiredEnabled": return target.isAutowiredEnabled();
case "block": return target.isBlock();
diff --git
a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java
b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java
index dca9b38c32b4..c2bcc106983b 100644
---
a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java
+++
b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java
@@ -23,6 +23,8 @@ public class KameletEndpointConfigurer extends
PropertyConfigurerSupport impleme
public boolean configure(CamelContext camelContext, Object obj, String
name, Object value, boolean ignoreCase) {
KameletEndpoint target = (KameletEndpoint) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
+ case "advancedoptions":
+ case "advancedOptions":
target.setAdvancedOptions(property(camelContext, boolean.class, value)); return
true;
case "block": target.setBlock(property(camelContext, boolean.class,
value)); return true;
case "bridgeerrorhandler":
case "bridgeErrorHandler":
target.setBridgeErrorHandler(property(camelContext, boolean.class, value));
return true;
@@ -45,6 +47,8 @@ public class KameletEndpointConfigurer extends
PropertyConfigurerSupport impleme
@Override
public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
+ case "advancedoptions":
+ case "advancedOptions": return boolean.class;
case "block": return boolean.class;
case "bridgeerrorhandler":
case "bridgeErrorHandler": return boolean.class;
@@ -68,6 +72,8 @@ public class KameletEndpointConfigurer extends
PropertyConfigurerSupport impleme
public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
KameletEndpoint target = (KameletEndpoint) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
+ case "advancedoptions":
+ case "advancedOptions": return target.isAdvancedOptions();
case "block": return target.isBlock();
case "bridgeerrorhandler":
case "bridgeErrorHandler": return target.isBridgeErrorHandler();
diff --git
a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointUriFactory.java
b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointUriFactory.java
index 8c90f38ab1fb..4aa844356921 100644
---
a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointUriFactory.java
+++
b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointUriFactory.java
@@ -24,7 +24,8 @@ public class KameletEndpointUriFactory extends
org.apache.camel.support.componen
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(11);
+ Set<String> props = new HashSet<>(12);
+ props.add("advancedOptions");
props.add("block");
props.add("bridgeErrorHandler");
props.add("exceptionHandler");
diff --git
a/components/camel-kamelet/src/generated/resources/META-INF/org/apache/camel/component/kamelet/kamelet.json
b/components/camel-kamelet/src/generated/resources/META-INF/org/apache/camel/component/kamelet/kamelet.json
index 753ec91c2cd4..14d0fbcb6a6c 100644
---
a/components/camel-kamelet/src/generated/resources/META-INF/org/apache/camel/component/kamelet/kamelet.json
+++
b/components/camel-kamelet/src/generated/resources/META-INF/org/apache/camel/component/kamelet/kamelet.json
@@ -31,9 +31,10 @@
"block": { "index": 4, "kind": "property", "displayName": "Block",
"group": "producer", "label": "producer", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": true, "description": "If sending a message to a kamelet
endpoint which has no active consumer, then we can tell the producer to block
and wait for the consumer to become active." },
"lazyStartProducer": { "index": 5, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the producer should be started lazy (on the first message). By
starting lazy you can use this to allow CamelContext and routes to startup in
situations where a producer may otherwise fail [...]
"timeout": { "index": 6, "kind": "property", "displayName": "Timeout",
"group": "producer", "label": "producer", "required": false, "type": "integer",
"javaType": "long", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 30000, "description": "The timeout value to use if block is
enabled." },
- "autowiredEnabled": { "index": 7, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
- "noErrorHandler": { "index": 8, "kind": "property", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs r [...]
- "routeTemplateLoaderListener": { "index": 9, "kind": "property",
"displayName": "Route Template Loader Listener", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.RouteTemplateLoaderListener", "deprecated": false,
"autowired": true, "secret": false, "description": "To plugin a custom listener
for when the Kamelet component is loading Kamelets from external resources." }
+ "advancedOptions": { "index": 7, "kind": "property", "displayName":
"Advanced Options", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to forward extra URI parameters to the endpoint wrapped by the
Kamelet. When enabled, parameters that are not Kamelet template properties or
reserved Kamelet options are appended to the wrappe [...]
+ "autowiredEnabled": { "index": 8, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "noErrorHandler": { "index": 9, "kind": "property", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs r [...]
+ "routeTemplateLoaderListener": { "index": 10, "kind": "property",
"displayName": "Route Template Loader Listener", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.RouteTemplateLoaderListener", "deprecated": false,
"autowired": true, "secret": false, "description": "To plugin a custom listener
for when the Kamelet component is loading Kamelets from external resources." }
},
"properties": {
"templateId": { "index": 0, "kind": "path", "displayName": "Template Id",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired":
false, "secret": false, "description": "The Route Template ID" },
@@ -45,7 +46,8 @@
"failIfNoConsumers": { "index": 6, "kind": "parameter", "displayName":
"Fail If No Consumers", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": true, "description": "Whether the producer should fail by
throwing an exception, when sending to a kamelet endpoint with no active
consumers." },
"lazyStartProducer": { "index": 7, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
"timeout": { "index": 8, "kind": "parameter", "displayName": "Timeout",
"group": "producer (advanced)", "label": "producer,advanced", "required":
false, "type": "integer", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": 30000, "description": "The timeout
value to use if block is enabled." },
- "location": { "index": 9, "kind": "parameter", "displayName": "Location",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "Location of the Kamelet to
use which can be specified as a resource from file system, classpath etc. The
location cannot use wildcards, and must refer to a file including extension,
for example file:\/etc\/ [...]
- "noErrorHandler": { "index": 10, "kind": "parameter", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs [...]
+ "advancedOptions": { "index": 9, "kind": "parameter", "displayName":
"Advanced Options", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to forward extra URI parameters to the endpoint wrapped by the
Kamelet. When enabled, parameters that are not Kamelet template properties or
reserved Kamelet options are appended to the wrapp [...]
+ "location": { "index": 10, "kind": "parameter", "displayName": "Location",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "Location of the Kamelet to
use which can be specified as a resource from file system, classpath etc. The
location cannot use wildcards, and must refer to a file including extension,
for example file:\/etc\ [...]
+ "noErrorHandler": { "index": 11, "kind": "parameter", "displayName": "No
Error Handler", "group": "advanced", "label": "advanced", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether kamelets
should use error handling or not. By default, the Kamelet uses the same error
handler as from the calling route. This means that if the calling route has
error handling that performs [...]
}
}
diff --git a/components/camel-kamelet/src/main/docs/kamelet-component.adoc
b/components/camel-kamelet/src/main/docs/kamelet-component.adoc
index dbf297fb88f6..2fd776e2bb9b 100644
--- a/components/camel-kamelet/src/main/docs/kamelet-component.adoc
+++ b/components/camel-kamelet/src/main/docs/kamelet-component.adoc
@@ -163,6 +163,72 @@ The usage of this Kamelet into a Camel route is going to
be the same as any othe
WARNING: beware of any potential circular reference you may introduce when
using chain of Kamelets, in which case, the runtime will likely be idle
consuming a high amount of resources.
+=== Advanced component endpoint options
+
+Kamelets expose a defined set of parameters, but the underlying Camel
component may support additional endpoint options.
+You can forward those options by enabling `advancedOptions` (disabled by
default).
+
+When enabled, extra URI parameters that are not Kamelet template properties
and not reserved Kamelet options
+(`routeId`, `templateId`, `location`, `advancedOptions`, and the other kamelet
endpoint options) are appended to the
+endpoint wrapped by the Kamelet.
+
+Enable the feature on the component, or on a single endpoint. The endpoint
setting overrides the component setting.
+
+[source,properties]
+----
+camel.component.kamelet.advanced-options=true
+----
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("kamelet:aws-s3-source?advancedOptions=true&bucketNameOrArn=x&maxConnections=100")
+ .to("log:info");
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: kamelet:aws-s3-source
+ parameters:
+ advancedOptions: true
+ bucketNameOrArn: x
+ maxConnections: 100
+ steps:
+ - to:
+ uri: log:info
+----
+====
+
+In this example, `bucketNameOrArn` is a template property of the Kamelet and
stays a template parameter.
+`maxConnections=100` is forwarded to the wrapped `aws2-s3` endpoint. If that
endpoint URI already contains the same option,
+the advanced option overrides its existing value.
+
+Source Kamelets forward extra options to their input endpoint. Sink and action
Kamelets forward extra options to the
+Kamelet's main `to()` endpoint.
+
+The options are applied only when the Kamelet has exactly one eligible
top-level, statically-defined `to()` destination.
+Kamelet endpoints and auxiliary destinations such as `wireTap()` are excluded.
Nested branch destinations, such as those
+inside `choice()` or `doTry()`, are not considered eligible main destinations.
+
+If an action Kamelet has no wrapped endpoint, or the Kamelet contains multiple
eligible top-level destinations, or it
+uses a dynamic destination such as `toD()`, `enrich()`, or `pollEnrich()`,
startup fails with an explanatory exception
+when advanced options are supplied. In these cases, configure the options
directly on the intended endpoint URI.
+
+Property placeholders and RAW expressions in endpoint URIs are preserved when
advanced options are applied. For example,
+`+kafka:{{topic}}+` or `+aws2-s3:{{bucket}}?secretKey=RAW({{secret}})+` remain
intact.
+
+The advanced options are forwarded as they are written in the Kamelet URI.
Percent-encoded values, `RAW(...)` values
+and repeated parameters reach the wrapped endpoint the same way as when the
options are set on that endpoint directly.
+
+When `advancedOptions` is disabled or omitted, the Kamelet retains its
existing configuration behavior.
+
== Examples
_Kamelets_ can be used as if they were standard Camel components.
@@ -219,7 +285,6 @@ YAML::
----
====
-
Behind the scenes, the *Kamelet* component does the following things:
1. it instantiates a route out of the Route Template identified by the given
`templateId` path parameter (in this case `setMyBody`)
diff --git
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
index 9a5acda98d16..94ad037801eb 100644
---
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
+++
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
@@ -16,20 +16,30 @@
*/
package org.apache.camel.component.kamelet;
+import java.net.URISyntaxException;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import java.util.StringJoiner;
import java.util.function.Predicate;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.NoErrorHandlerBuilder;
+import org.apache.camel.model.EnrichDefinition;
import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.PollEnrichDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.ProcessorDefinitionHelper;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RouteTemplateDefinition;
+import org.apache.camel.model.RouteTemplateParameterDefinition;
import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.ToDynamicDefinition;
+import org.apache.camel.model.WireTapDefinition;
import org.apache.camel.spi.PropertiesComponent;
import org.apache.camel.spi.UuidGenerator;
import org.apache.camel.support.CamelContextHelper;
@@ -37,6 +47,7 @@ import org.apache.camel.support.SimpleUuidGenerator;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
+import org.apache.camel.util.URISupport;
import static
org.apache.camel.model.ProcessorDefinitionHelper.filterTypeInOutputs;
@@ -55,6 +66,7 @@ public final class Kamelet {
public static final String PARENT_PROCESSOR_ID = "parentProcessorId";
public static final String NO_ERROR_HANDLER = "noErrorHandler";
public static final String BRIDGE_ERROR_HANDLER = "bridgeErrorHandler";
+ static final String ADVANCED_OPTIONS = "internal.advanced.options";
// use a running counter as uuid
private static final UuidGenerator UUID = new SimpleUuidGenerator();
@@ -62,6 +74,18 @@ public final class Kamelet {
private Kamelet() {
}
+ private static boolean isKameletEndpoint(String uri, String endpoint) {
+ if (uri == null) {
+ return false;
+ }
+ return uri.equals("kamelet:" + endpoint)
+ || uri.startsWith("kamelet:" + endpoint + "?")
+ || uri.startsWith("kamelet:" + endpoint + "/")
+ || uri.equals("kamelet://" + endpoint)
+ || uri.startsWith("kamelet://" + endpoint + "?")
+ || uri.startsWith("kamelet://" + endpoint + "/");
+ }
+
public static Predicate<String> startsWith(String prefix) {
return item -> item.startsWith(prefix);
}
@@ -184,6 +208,241 @@ public final class Kamelet {
}
}
+ /**
+ * Reads the original advanced options map stored under a single internal
key.
+ */
+ private static Map<String, Object> extractAdvancedOptions(Map<String,
Object> parameters, String key) {
+ Map<String, Object> options = new LinkedHashMap<>();
+ if (parameters == null) {
+ return options;
+ }
+
+ Object value = parameters.get(key);
+ if (value instanceof Map<?, ?> map) {
+ for (Map.Entry<?, ?> entry : map.entrySet()) {
+ if (entry.getKey() != null) {
+ options.put(entry.getKey().toString(), entry.getValue());
+ }
+ }
+ }
+
+ return options;
+ }
+
+ /**
+ * Drops Kamelet template properties from the advanced-option candidates,
treating camelCase and kebab-case names as
+ * aliases the same way {@code DefaultModel} does for route templates.
+ */
+ private static Map<String, Object> excludeTemplateParameters(
+ Map<String, Object> candidates, RouteTemplateDefinition template) {
+ if (candidates == null || candidates.isEmpty()) {
+ return new LinkedHashMap<>();
+ }
+
+ Set<String> templateNames = templateParameterNames(template);
+ if (templateNames.isEmpty()) {
+ return candidates;
+ }
+
+ Map<String, Object> filtered = new LinkedHashMap<>();
+ for (Map.Entry<String, Object> entry : candidates.entrySet()) {
+ String name = entry.getKey();
+ if (name != null && !isTemplateParameter(name, templateNames)) {
+ filtered.put(name, entry.getValue());
+ }
+ }
+ return filtered;
+ }
+
+ private static Set<String> templateParameterNames(RouteTemplateDefinition
template) {
+ Set<String> names = new HashSet<>();
+ if (template == null || template.getTemplateParameters() == null) {
+ return names;
+ }
+ for (RouteTemplateParameterDefinition param :
template.getTemplateParameters()) {
+ if (param.getName() != null) {
+ names.add(param.getName());
+ names.add(StringHelper.dashToCamelCase(param.getName()));
+ names.add(StringHelper.camelCaseToDash(param.getName()));
+ }
+ }
+ return names;
+ }
+
+ private static boolean isTemplateParameter(String name, Set<String>
templateNames) {
+ return templateNames.contains(name)
+ || templateNames.contains(StringHelper.dashToCamelCase(name))
+ || templateNames.contains(StringHelper.camelCaseToDash(name));
+ }
+
+ /**
+ * Preserves the user-supplied option name. When both camelCase and
kebab-case forms are present, the kebab-case
+ * form is kept so the same option is not appended twice.
+ */
+ private static Map<String, Object> normalizeParameterNames(Map<String,
Object> parameters) {
+ Map<String, Object> normalized = new LinkedHashMap<>();
+ Map<String, String> seenOriginal = new HashMap<>();
+ Map<String, Boolean> seenIsCanonical = new HashMap<>();
+
+ if (parameters == null) {
+ return normalized;
+ }
+
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ String originalName = entry.getKey();
+ String name = StringHelper.camelCaseToDash(originalName);
+ boolean isCanonical = originalName.equals(name);
+
+ String existingOriginal = seenOriginal.get(name);
+ if (existingOriginal == null) {
+ seenOriginal.put(name, originalName);
+ seenIsCanonical.put(name, isCanonical);
+ normalized.put(originalName, entry.getValue());
+ } else {
+ boolean existingIsCanonical = seenIsCanonical.get(name);
+ if (isCanonical && !existingIsCanonical) {
+ normalized.remove(existingOriginal);
+ seenOriginal.put(name, originalName);
+ seenIsCanonical.put(name, isCanonical);
+ normalized.put(originalName, entry.getValue());
+ }
+ }
+ }
+
+ return normalized;
+ }
+
+ /**
+ * Appends the advanced options to the endpoint URI. The option values are
the text as written in the Kamelet URI
+ * (percent-encoding and RAW(...) kept), so they are already valid URI
text and are appended as is. Property
+ * placeholders and RAW expressions in the endpoint URI are preserved.
+ */
+ private static String appendParametersToURI(String uri, Map<String,
Object> parameters) {
+ if (parameters == null || parameters.isEmpty()) {
+ return uri;
+ }
+
+ String result = uri;
+
+ // First remove all parameters that will be overridden.
+ for (String name : parameters.keySet()) {
+ result = removeQueryParameter(result, name);
+ }
+
+ char sep = result.indexOf('?') < 0 ? '?' : '&';
+ return result + sep + toQueryString(parameters);
+ }
+
+ /**
+ * Removes a query parameter by name, treating camelCase and kebab-case
names as aliases. The query is split with
+ * {@link URISupport#parseQuery(String, boolean, boolean)} in raw mode,
which is how Camel itself reads an endpoint
+ * URI, and which keeps the values as written. The URI is returned
unchanged when the parameter is not present.
+ */
+ static String removeQueryParameter(String uri, String parameterName) {
+ int queryIndex = uri.indexOf('?');
+ if (queryIndex < 0) {
+ return uri;
+ }
+
+ Map<String, Object> query;
+ try {
+ query = URISupport.parseQuery(uri.substring(queryIndex + 1), true,
true);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Invalid endpoint URI: " +
URISupport.sanitizeUri(uri), e);
+ }
+
+ String normalizedName = StringHelper.camelCaseToDash(parameterName);
+ if (!query.keySet().removeIf(key ->
StringHelper.camelCaseToDash(key).equals(normalizedName))) {
+ return uri;
+ }
+
+ String base = uri.substring(0, queryIndex);
+ return query.isEmpty() ? base : base + "?" + toQueryString(query);
+ }
+
+ /**
+ * Builds a query string from values that are already URI text, so nothing
is encoded. A repeated parameter (a
+ * collection value) is written once per value.
+ */
+ private static String toQueryString(Map<String, Object> parameters) {
+ StringJoiner sj = new StringJoiner("&");
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ if (entry.getValue() instanceof Collection<?> values) {
+ values.forEach(value -> sj.add(entry.getKey() + "=" + value));
+ } else if (entry.getValue() != null) {
+ sj.add(entry.getKey() + "=" + entry.getValue());
+ } else {
+ sj.add(entry.getKey());
+ }
+ }
+ return sj.toString();
+ }
+
+ /**
+ * Finds a single statically defined main sink among top-level outputs.
+ *
+ * <p>
+ * Endpoint schemes are deliberately not used to guess whether a
destination is auxiliary. A log or direct endpoint
+ * can be a legitimate destination, and scheme-based exclusions can select
the wrong endpoint. Only top-level static
+ * to() destinations are considered; destinations inside branches and
WireTap are not.
+ *
+ * @throws IllegalArgumentException if more than one candidate exists,
because the intended sink cannot be
+ * determined unambiguously
+ */
+ private static ToDefinition
findMainSink(Collection<ProcessorDefinition<?>> outputs) {
+ if (outputs == null) {
+ return null;
+ }
+
+ ToDefinition mainSink = null;
+
+ for (ProcessorDefinition<?> output : outputs) {
+ if (output instanceof WireTapDefinition) {
+ continue;
+ }
+
+ if (output instanceof ToDefinition to
+ && to.getEndpointUri() != null
+ && !to.getEndpointUri().startsWith("kamelet:")) {
+ if (mainSink != null) {
+ throw new IllegalArgumentException(
+ "advancedOptions cannot be applied because the
Kamelet has multiple "
+ + "top-level static
to() destinations. Configure the options directly on the "
+ + "intended destination
endpoint URI.");
+ }
+ mainSink = to;
+ }
+ }
+
+ return mainSink;
+ }
+
+ /**
+ * Returns whether the processor tree contains a dynamic destination that
cannot be configured by appending options
+ * to a static to() endpoint. WireTap is excluded because it is an
auxiliary destination.
+ */
+ private static boolean
hasUnsupportedDynamicSinkTarget(Collection<ProcessorDefinition<?>> outputs) {
+ if (outputs == null) {
+ return false;
+ }
+
+ for (ProcessorDefinition<?> output : outputs) {
+ if (output instanceof WireTapDefinition) {
+ continue;
+ }
+ if (output instanceof ToDynamicDefinition
+ || output instanceof EnrichDefinition
+ || output instanceof PollEnrichDefinition) {
+ return true;
+ }
+ if (hasUnsupportedDynamicSinkTarget(output.getOutputs())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public static RouteDefinition templateToRoute(RouteTemplateDefinition in,
Map<String, Object> parameters) {
final String rid = (String) parameters.get(PARAM_ROUTE_ID);
final boolean noErrorHandler = (boolean)
parameters.get(NO_ERROR_HANDLER);
@@ -230,9 +489,58 @@ public final class Kamelet {
throw new IllegalArgumentException("Camel route " + rid + " input
does not exist.");
}
- // must make the source and sink endpoints are unique by appending the
route id before we create the route from the template
- if (def.getInput().getEndpointUri().startsWith("kamelet:source")
- ||
def.getInput().getEndpointUri().startsWith("kamelet://source")) {
+ // Extract advanced options from the unified internal.advanced.options
map, then drop
+ // Kamelet template properties so they stay available for placeholder
resolution.
+ Map<String, Object> advancedOptions = normalizeParameterNames(
+ excludeTemplateParameters(extractAdvancedOptions(parameters,
ADVANCED_OPTIONS), in));
+
+ // Determine Kamelet type: source Kamelets have a real component as
input;
+ // sink/action Kamelets have kamelet:source as input and the real
component in outputs.
+ boolean isSourceKamelet =
!isKameletEndpoint(def.getInput().getEndpointUri(), SOURCE_ID);
+
+ if (isSourceKamelet) {
+ // Source Kamelet: the real component endpoint is the input.
+ if (!advancedOptions.isEmpty()) {
+ String uri = def.getInput().getEndpointUri();
+ try {
+ def.getInput().setUri(appendParametersToURI(uri,
advancedOptions));
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "Failed to apply advanced options to endpoint URI:
" + uri, e);
+ }
+ }
+ } else {
+ // Sink/action Kamelet: the real component endpoint is in the
outputs.
+ if (!advancedOptions.isEmpty()) {
+ // If a dynamic destination exists, the intended static
destination cannot be determined reliably.
+ if (hasUnsupportedDynamicSinkTarget(def.getOutputs())) {
+ throw new IllegalArgumentException(
+ "advancedOptions cannot be applied because this
Kamelet contains a dynamic "
+ + "destination (toD,
enrich, or pollEnrich). Configure the options directly "
+ + "in the destination
endpoint URI.");
+ }
+
+ ToDefinition mainSink = findMainSink(def.getOutputs());
+
+ if (mainSink == null) {
+ throw new IllegalArgumentException(
+ "advancedOptions cannot be applied because the
Kamelet has no top-level "
+ + "static to()
destination. Configure the options directly on the destination "
+ + "endpoint URI.");
+ }
+
+ String uri = mainSink.getEndpointUri();
+ try {
+ mainSink.setUri(appendParametersToURI(uri,
advancedOptions));
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "Failed to apply advanced options to endpoint URI:
" + uri, e);
+ }
+ }
+ }
+
+ // Make source and sink endpoints unique by appending the route ID
before creating the route from the template.
+ if (isKameletEndpoint(def.getInput().getEndpointUri(), SOURCE_ID)) {
def.getInput().setUri("kamelet://source?" + PARAM_ROUTE_ID + "=" +
rid);
}
@@ -253,7 +561,7 @@ public final class Kamelet {
boolean sink = false;
Collection<ToDefinition> col = filterTypeInOutputs(def.getOutputs(),
ToDefinition.class);
for (ToDefinition to : col) {
- if (to.getEndpointUri().startsWith("kamelet:sink") ||
to.getEndpointUri().startsWith("kamelet://sink")) {
+ if (isKameletEndpoint(to.getEndpointUri(), SINK_ID)) {
to.setUri("kamelet://sink?" + PARAM_ROUTE_ID + "=" + rid);
sink = true;
}
diff --git
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
index c3eccedc5a91..580b85b105b9 100644
---
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
+++
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -51,6 +52,7 @@ import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.camel.component.kamelet.Kamelet.ADVANCED_OPTIONS;
import static org.apache.camel.component.kamelet.Kamelet.BRIDGE_ERROR_HANDLER;
import static org.apache.camel.component.kamelet.Kamelet.NO_ERROR_HANDLER;
import static org.apache.camel.component.kamelet.Kamelet.PARAM_LOCATION;
@@ -103,6 +105,10 @@ public class KameletComponent extends DefaultComponent {
@Metadata(defaultValue = Kamelet.DEFAULT_LOCATION)
private String location = Kamelet.DEFAULT_LOCATION;
+ @Metadata(label = "advanced", defaultValue = "false",
+ description = "Whether to forward extra URI parameters to the
endpoint wrapped by the Kamelet. When enabled, parameters that are not Kamelet
template properties or reserved Kamelet options are appended to the wrapped
source or sink endpoint. Disabled by default.")
+ private boolean advancedOptions;
+
public KameletComponent() {
}
@@ -141,6 +147,8 @@ public class KameletComponent extends DefaultComponent {
// resolveRawParameterValues is false
// this ensures that parameters such as passwords are used as-is and
not encoded
// but this requires to use RAW() syntax in the kamelet template.
+ // keep the values as written first (useRawUri), as advanced options
are forwarded as URI text
+ final Map<String, Object> rawParameters = copyParameters(parameters);
URISupport.resolveRawParameterValues(parameters);
final KameletEndpoint endpoint;
@@ -174,6 +182,7 @@ public class KameletComponent extends DefaultComponent {
endpoint.setTimeout(timeout);
// endpoint specific location
endpoint.setLocation(loc);
+ endpoint.setAdvancedOptions(advancedOptions);
// set endpoint specific properties
setProperties(endpoint, parameters);
@@ -198,6 +207,7 @@ public class KameletComponent extends DefaultComponent {
endpoint.setTimeout(timeout);
// endpoint specific location
endpoint.setLocation(loc);
+ endpoint.setAdvancedOptions(advancedOptions);
// set and remove endpoint specific properties
setProperties(endpoint, parameters);
@@ -250,6 +260,16 @@ public class KameletComponent extends DefaultComponent {
//
Kamelet.extractKameletEnvironmentVariables(kameletProperties,
templateId, routeId);
+ // Snapshot remaining URI parameters as advanced-option candidates
when enabled. Template
+ // parameters are filtered later in templateToRoute, after the
template is loaded. Only URI
+ // leftovers are candidates, not camel.kamelet.* or environment
properties. The values are
+ // taken as written in the URI (percent-encoding and RAW(...)
kept), so they can be appended
+ // to the wrapped endpoint URI as is.
+ Map<String, Object> advancedParamOptions = new LinkedHashMap<>();
+ if (endpoint.isAdvancedOptions()) {
+ parameters.keySet().forEach(key ->
advancedParamOptions.put(key, rawParameters.get(key)));
+ }
+
//
// Uri params have the highest precedence
//
@@ -264,6 +284,15 @@ public class KameletComponent extends DefaultComponent {
kameletProperties.put(NO_ERROR_HANDLER,
endpoint.isNoErrorHandler());
kameletProperties.put(BRIDGE_ERROR_HANDLER,
endpoint.isBridgeErrorHandler());
+ // Remove any route-scoped properties that might have used the
internal prefix
+ // to prevent users from bypassing the intended separation
+ kameletProperties.keySet().removeIf(key ->
key.startsWith("internal.advanced."));
+
+ // Pass the original option map as a single value so inner keys
keep the user-supplied spelling
+ if (!advancedParamOptions.isEmpty()) {
+ kameletProperties.put(ADVANCED_OPTIONS, advancedParamOptions);
+ }
+
// set kamelet specific properties
endpoint.setKameletProperties(kameletProperties);
@@ -284,6 +313,13 @@ public class KameletComponent extends DefaultComponent {
return false;
}
+ private static Map<String, Object> copyParameters(Map<String, Object>
parameters) {
+ // resolveRawParameterValues updates repeated parameters (lists) in
place, so copy those too
+ Map<String, Object> answer = new LinkedHashMap<>();
+ parameters.forEach((key, value) -> answer.put(key, value instanceof
List<?> list ? new ArrayList<>(list) : value));
+ return answer;
+ }
+
public boolean isNoErrorHandler() {
return noErrorHandler;
}
@@ -372,6 +408,19 @@ public class KameletComponent extends DefaultComponent {
return stateCounter;
}
+ public boolean isAdvancedOptions() {
+ return advancedOptions;
+ }
+
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by the
Kamelet. When enabled, parameters that are
+ * not Kamelet template properties or reserved Kamelet options are
appended to the wrapped source or sink endpoint.
+ * Disabled by default.
+ */
+ public void setAdvancedOptions(boolean advancedOptions) {
+ this.advancedOptions = advancedOptions;
+ }
+
public void addConsumer(String key, KameletConsumer consumer) {
consumersLock.lock();
try {
diff --git
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
index f92dedfea862..943f6fe5c129 100644
---
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
+++
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
@@ -60,6 +60,9 @@ public class KameletEndpoint extends DefaultEndpoint
implements AfterPropertiesC
private boolean failIfNoConsumers = true;
@UriParam(label = "advanced")
private boolean noErrorHandler;
+ @UriParam(label = "advanced", defaultValue = "false",
+ description = "Whether to forward extra URI parameters to the
endpoint wrapped by the Kamelet. When enabled, parameters that are not Kamelet
template properties or reserved Kamelet options are appended to the wrapped
source or sink endpoint. Disabled by default.")
+ private boolean advancedOptions;
public KameletEndpoint(String uri,
KameletComponent component,
@@ -77,6 +80,19 @@ public class KameletEndpoint extends DefaultEndpoint
implements AfterPropertiesC
this.kameletProperties = new HashMap<>();
}
+ public boolean isAdvancedOptions() {
+ return advancedOptions;
+ }
+
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by the
Kamelet. When enabled, parameters that are
+ * not Kamelet template properties or reserved Kamelet options are
appended to the wrapped source or sink endpoint.
+ * Disabled by default.
+ */
+ public void setAdvancedOptions(boolean advancedOptions) {
+ this.advancedOptions = advancedOptions;
+ }
+
public boolean isNoErrorHandler() {
return noErrorHandler;
}
diff --git
a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletAdvancedOptionsTest.java
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletAdvancedOptionsTest.java
new file mode 100644
index 000000000000..6882985cc7c0
--- /dev/null
+++
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletAdvancedOptionsTest.java
@@ -0,0 +1,1473 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kamelet;
+
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Pattern;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpEndpoint;
+import org.apache.camel.component.mock.MockComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.camel.util.URISupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class KameletAdvancedOptionsTest extends CamelTestSupport {
+
+ @Test
+ void advancedSourceOptionsAreApplied() {
+ RouteDefinition route = getRoute("sourceTrigger");
+ assertNotNull(route, "Expected the source caller route to be created");
+
+ String inputUri = findExpandedInputUri("direct:source?");
+ assertTrue(inputUri.contains("synchronous=true"),
+ () -> "Expected synchronous=true on the expanded source
endpoint, but was: " + inputUri);
+ }
+
+ @Test
+ void advancedSourceOptionsOverrideExistingUriParameters() {
+ RouteDefinition route = getRoute("sourceOverrideTrigger");
+ assertNotNull(route, "Expected the source override caller route to be
created");
+
+ String inputUri = findExpandedInputUri("direct:source-with-options?");
+ assertTrue(inputUri.contains("synchronous=true"),
+ () -> "Expected synchronous=true to override
synchronous=false: " + inputUri);
+ assertFalse(inputUri.contains("synchronous=false"),
+ () -> "The old synchronous=false value must not remain: " +
inputUri);
+ }
+
+ @Test
+ void advancedSourceOptionsPreservePropertyPlaceholders() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("source-with-placeholder")
+
.from("direct:source?synchronous=false&timeout={{timeout}}")
+ .to("kamelet:sink");
+
+ from("direct:trigger")
+
.to("kamelet:source-with-placeholder/test?advancedOptions=true&synchronous=true");
+ }
+ });
+
+ Properties properties = new Properties();
+ properties.put("timeout", "1000");
+
testContext.getPropertiesComponent().setInitialProperties(properties);
+ testContext.start();
+
+ RouteDefinition expandedRoute = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> route.getInput() != null)
+ .filter(route -> route.getInput().getEndpointUri() != null
+ &&
route.getInput().getEndpointUri().startsWith("direct:source?"))
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded source
route not found"));
+
+ String uri = expandedRoute.getInput().getEndpointUri();
+ assertTrue(uri.contains("synchronous=true"),
+ () -> "Expected advanced option, but was: " + uri);
+ assertTrue(uri.contains("timeout={{timeout}}"),
+ () -> "Expected the property placeholder to remain intact:
" + uri);
+ }
+ }
+
+ @Test
+ void advancedSourceOptionsPreserveRawExpressions() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("source-with-raw")
+ .from("direct:source?timeout=RAW({{secret}})")
+ .to("kamelet:sink");
+
+ from("direct:trigger")
+
.to("kamelet:source-with-raw/test?advancedOptions=true&synchronous=true");
+ }
+ });
+
+ Properties properties = new Properties();
+ properties.put("secret", "1000");
+
testContext.getPropertiesComponent().setInitialProperties(properties);
+ testContext.start();
+
+ RouteDefinition expandedRoute = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> route.getInput() != null)
+ .filter(route -> route.getInput().getEndpointUri() != null
+ &&
route.getInput().getEndpointUri().startsWith("direct:source?"))
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded source
route not found"));
+
+ String uri = expandedRoute.getInput().getEndpointUri();
+ assertTrue(uri.contains("synchronous=true"),
+ () -> "Expected advanced option, but was: " + uri);
+ assertTrue(uri.contains("timeout=RAW({{secret}})"),
+ () -> "Expected the RAW expression to remain intact: " +
uri);
+ }
+ }
+
+ @Test
+ void advancedSinkOptionsPreservePropertyPlaceholders() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-with-placeholder")
+ .from("kamelet:source")
+ .to("mock:{{topic}}?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("sink-with-placeholder?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Properties properties = new Properties();
+ properties.put("topic", "placeholder-sink");
+
testContext.getPropertiesComponent().setInitialProperties(properties);
+ testContext.start();
+
+ RouteDefinition expandedRoute = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> findToDefinition(route, "mock:{{topic}}")
!= null)
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded sink route
not found"));
+
+ ToDefinition sink = findToDefinition(expandedRoute,
"mock:{{topic}}");
+ assertNotNull(sink, "Expected the placeholder sink endpoint");
+
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("{{topic}}"),
+ () -> "Expected the property placeholder to remain intact:
" + uri);
+ assertTrue(uri.contains("retain-first=1"),
+ () -> "Expected the advanced option on the sink endpoint:
" + uri);
+ assertFalse(uri.contains("%7B%7Btopic%7D%7D"),
+ () -> "The placeholder must not be URL-encoded: " + uri);
+ }
+ }
+
+ @Test
+ void advancedSinkOptionsPreserveRawExpressions() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-with-raw")
+ .from("kamelet:source")
+ .to("mock:{{bucket}}?secretKey=RAW({{secret}})");
+
+ from("direct:trigger")
+
.kamelet("sink-with-raw?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Properties properties = new Properties();
+ properties.put("bucket", "placeholder-bucket");
+ properties.put("secret", "secret-value");
+
testContext.getPropertiesComponent().setInitialProperties(properties);
+ testContext.start();
+
+ RouteDefinition expandedRoute = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> route.getOutputs() != null)
+ .filter(route -> route.getOutputs().stream()
+ .anyMatch(output -> output instanceof ToDefinition
+ && ((ToDefinition)
output).getEndpointUri() != null
+ && ((ToDefinition)
output).getEndpointUri().startsWith("mock:{{bucket}}")))
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded RAW sink
route not found"));
+
+ ToDefinition sink = findToDefinition(expandedRoute,
"mock:{{bucket}}");
+ assertNotNull(sink, "Expected the RAW sink endpoint");
+
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("{{bucket}}"),
+ () -> "Expected the bucket placeholder to remain intact: "
+ uri);
+ assertTrue(uri.contains("secretKey=RAW({{secret}})"),
+ () -> "Expected the RAW expression to remain intact: " +
uri);
+ assertTrue(uri.contains("retain-first=1"),
+ () -> "Expected the advanced option on the sink endpoint:
" + uri);
+ assertFalse(uri.contains("%7B%7B"),
+ () -> "Property placeholders must not be URL-encoded: " +
uri);
+ }
+ }
+
+ @Test
+ void advancedSinkOptionsAreAppliedAndMessageIsDelivered() throws Exception
{
+ MockEndpoint sink = getMockEndpoint("mock:advanced-sink-result");
+ sink.expectedBodiesReceived("hello");
+
+ template.sendBody("direct:sink-trigger", "hello");
+
+ sink.assertIsSatisfied();
+ assertEquals(1, sink.getRetainFirst(),
+ "Expected retain-first=1 on the configured sink endpoint");
+ assertEquals(5, sink.getRetainLast(),
+ "Expected retain-last=5 to be preserved on the configured sink
endpoint");
+ }
+
+ @Test
+ void noAdvancedOptionsRetainsExistingBehavior() throws Exception {
+ MockEndpoint sink = getMockEndpoint("mock:basic-sink-result");
+ sink.expectedBodiesReceived("hello");
+
+ template.sendBody("direct:basic-trigger", "hello");
+
+ sink.assertIsSatisfied();
+ assertEquals(-1, sink.getRetainFirst(),
+ "The basic sink should retain the default retainFirst value");
+ assertEquals(-1, sink.getRetainLast(),
+ "The basic sink should retain the default retainLast value");
+ }
+
+ @Test
+ void advancedOptionsDoNotLeakBetweenInstancesOfTheSameKamelet() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("shared-sink")
+ .from("kamelet:source")
+ .to("mock:shared-sink?retain-first=0");
+
+ from("direct:with-options")
+
.kamelet("shared-sink/withOptions?advancedOptions=true&retain-first=1");
+
+ from("direct:without-options")
+ .kamelet("shared-sink/withoutOptions");
+ }
+ });
+
+ testContext.start();
+
+ List<String> uris = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .map(route -> findToDefinition(route, "mock:shared-sink"))
+ .filter(sink -> sink != null)
+ .map(ToDefinition::getEndpointUri)
+ .toList();
+
+ assertEquals(2, uris.size(), () -> "Expected two expanded
shared-sink instances: " + uris);
+ assertTrue(uris.stream().anyMatch(uri ->
uri.contains("retain-first=1")),
+ () -> "The instance with advancedOptions should receive
retain-first=1: " + uris);
+ assertTrue(uris.stream().anyMatch(uri ->
uri.contains("retain-first=0") && !uri.contains("retain-first=1")),
+ () -> "The instance without advancedOptions must keep
retain-first=0: " + uris);
+ }
+ }
+
+ @Test
+ void extraParametersWithoutAdvancedOptionsAreNotForwarded() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-without-flag")
+ .from("kamelet:source")
+ .to("mock:no-flag-sink?retain-first=0");
+
+ from("direct:trigger")
+ .kamelet("sink-without-flag?retain-first=1");
+ }
+ });
+
+ testContext.start();
+
+ ToDefinition sink = findToDefinition(
+ findExpandedRouteWithOutput(testContext,
"mock:no-flag-sink"), "mock:no-flag-sink");
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("retain-first=0"),
+ () -> "Without advancedOptions the original value must
remain: " + uri);
+ assertFalse(uri.contains("retain-first=1"),
+ () -> "Without advancedOptions extra URI parameters must
not be forwarded: " + uri);
+ }
+ }
+
+ @Test
+ void componentAdvancedOptionsForwardsWithoutEndpointFlag() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.getComponent("kamelet",
KameletComponent.class).setAdvancedOptions(true);
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("component-sink")
+ .from("kamelet:source")
+ .to("mock:component-sink?retain-first=0");
+
+ from("direct:trigger")
+ .kamelet("component-sink?retain-first=1");
+ }
+ });
+
+ testContext.start();
+
+ ToDefinition sink = findToDefinition(
+ findExpandedRouteWithOutput(testContext,
"mock:component-sink"), "mock:component-sink");
+ assertNotNull(sink, "Expected sink endpoint");
+ assertTrue(sink.getEndpointUri().contains("retain-first=1"),
+ () -> "Component advancedOptions=true should forward extra
parameters: "
+ + sink.getEndpointUri());
+ }
+ }
+
+ @Test
+ void endpointAdvancedOptionsFalseOverridesComponent() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.getComponent("kamelet",
KameletComponent.class).setAdvancedOptions(true);
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("endpoint-override-sink")
+ .from("kamelet:source")
+ .to("mock:endpoint-override-sink?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("endpoint-override-sink?advancedOptions=false&retain-first=1");
+ }
+ });
+
+ testContext.start();
+
+ ToDefinition sink = findToDefinition(
+ findExpandedRouteWithOutput(testContext,
"mock:endpoint-override-sink"),
+ "mock:endpoint-override-sink");
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("retain-first=0"),
+ () -> "Endpoint advancedOptions=false must keep the
original value: " + uri);
+ assertFalse(uri.contains("retain-first=1"),
+ () -> "Endpoint advancedOptions=false must override the
component: " + uri);
+ }
+ }
+
+ @Test
+ void templatePropertiesAreNotForwardedOnSource() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("source-with-param")
+ .templateParameter("name")
+ .from("direct:{{name}}?synchronous=false")
+ .to("kamelet:sink");
+
+ from("direct:trigger")
+
.to("kamelet:source-with-param?advancedOptions=true&name=foo&synchronous=true");
+ }
+ });
+
+ testContext.start();
+
+ String uri = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> route.getInput() != null)
+ .map(route -> route.getInput().getEndpointUri())
+ .filter(endpointUri -> endpointUri != null &&
endpointUri.contains("synchronous=true"))
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded source
route not found"));
+
+ assertTrue(uri.startsWith("direct:foo") ||
uri.startsWith("direct:{{name}}"),
+ () -> "Expected the template property to be used as the
source path: " + uri);
+ assertFalse(uri.contains("name="),
+ () -> "Template property name must not be forwarded as a
query parameter: " + uri);
+ }
+ }
+
+ @Test
+ void templatePropertiesAreNotForwardedOnSink() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-with-param")
+ .templateParameter("topic")
+ .from("kamelet:source")
+ .to("mock:{{topic}}?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("sink-with-param?advancedOptions=true&topic=out&retain-first=1");
+ }
+ });
+
+ testContext.start();
+
+ ToDefinition sink = findToDefinition(
+ findExpandedRouteWithOutput(testContext,
"mock:{{topic}}"), "mock:{{topic}}");
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("retain-first=1"),
+ () -> "Expected the advanced option on the sink endpoint:
" + uri);
+ Map<String, Object> query = parseUriQuery(uri);
+ assertFalse(query.containsKey("topic"),
+ () -> "Template property topic must not be forwarded as a
query parameter: " + uri);
+ }
+ }
+
+ @Test
+ void reservedOptionsAndSwitchAreNotForwarded() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("reserved-sink")
+ .from("kamelet:source")
+ .to("mock:reserved-sink?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("reserved-sink?advancedOptions=true&retain-first=1&location=classpath:kamelets");
+ }
+ });
+
+ testContext.start();
+
+ ToDefinition sink = findToDefinition(
+ findExpandedRouteWithOutput(testContext,
"mock:reserved-sink"), "mock:reserved-sink");
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("retain-first=1"),
+ () -> "Expected the advanced option on the sink endpoint:
" + uri);
+ assertFalse(uri.contains("advancedOptions="),
+ () -> "The advancedOptions switch must not be forwarded: "
+ uri);
+ assertFalse(uri.contains("location="),
+ () -> "Reserved option location must not be forwarded: " +
uri);
+ }
+ }
+
+ @Test
+ void actionWithoutWrappedEndpointFailsWhenAdvancedOptionsSupplied() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("set-body-action")
+ .from("kamelet:source")
+ .setBody().constant("x");
+
+ from("direct:trigger")
+
.kamelet("set-body-action?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException for an action
without a wrapped endpoint, but got: "
+ + exception);
+ assertTrue(exceptionChainContains(exception, "no top-level static
to() destination"),
+ () -> "Expected a clear no-wrapped-endpoint error, but
got: " + exception);
+ }
+ }
+
+ @Test
+ void sourceKameletForwardsUnprefixedOptions() throws Exception {
+ try (CamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("source-with-unprefixed-options")
+ .from("direct:source")
+ .to("kamelet:sink");
+
+ from("direct:trigger")
+
.to("kamelet:source-with-unprefixed-options/test?advancedOptions=true&synchronous=true");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> route.getInput() != null)
+ .filter(route -> route.getInput().getEndpointUri() != null
+ &&
route.getInput().getEndpointUri().startsWith("direct:source?"))
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded source
route not found"));
+
+ String uri = expandedRoute.getInput().getEndpointUri();
+ assertTrue(uri.contains("synchronous=true"),
+ () -> "Expected advanced option on source endpoint: " +
uri);
+ }
+ }
+
+ @Test
+ void sinkKameletForwardsUnprefixedOptions() throws Exception {
+ try (CamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-with-unprefixed-options")
+ .from("kamelet:source")
+ .to("mock:result");
+
+ from("direct:trigger")
+
.kamelet("sink-with-unprefixed-options?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute = ((ModelCamelContext)
testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> findToDefinition(route, "mock:result") !=
null)
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded sink route
not found"));
+
+ ToDefinition sink = findToDefinition(expandedRoute, "mock:result");
+ assertNotNull(sink, "Expected the sink endpoint");
+
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("retain-first=1"),
+ () -> "Expected advanced option on sink endpoint: " + uri);
+ }
+ }
+
+ @Test
+ void advancedSinkOptionsRejectMultipleTopLevelStaticDestinations() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("mock-multi-sink")
+ .from("kamelet:source")
+ .to("mock:first-advanced-sink?retain-first=0")
+ .to("mock:second-advanced-sink?retain-first=0");
+
+ from("direct:multi-sink-trigger")
+
.kamelet("mock-multi-sink?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException for multiple
destinations, but got: " + exception);
+ assertTrue(exceptionChainContains(exception, "multiple top-level
static to() destinations"),
+ () -> "Expected a clear ambiguity error, but got: " +
exception);
+ }
+ }
+
+ @Test
+ void advancedSinkOptionsRejectNestedChoiceDestinations() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("choice-sink")
+ .from("kamelet:source")
+ .choice()
+ .when(header("selected").isEqualTo(true))
+ .to("mock:choice-selected?retain-first=0")
+ .otherwise()
+ .to("mock:choice-default?retain-first=0")
+ .end();
+
+ from("direct:trigger")
+
.kamelet("choice-sink?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException for nested
destinations, but got: " + exception);
+ assertTrue(exceptionChainContains(exception, "no top-level static
to() destination"),
+ () -> "Expected a clear no-static-sink error, but got: " +
exception);
+ }
+ }
+
+ @Test
+ void sinkOptionsNormalizeDuplicateCamelCaseAndKebabCaseNames() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-with-duplicate-options")
+ .from("kamelet:source")
+ .to("mock:duplicate-options?retain-first=0");
+
+ from("direct:trigger")
+ .kamelet(
+
"sink-with-duplicate-options?advancedOptions=true&retainFirst=1&retain-first=2");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute = findExpandedRouteWithOutput(
+ testContext, "mock:duplicate-options");
+ ToDefinition sink = findToDefinition(expandedRoute,
"mock:duplicate-options");
+
+ assertNotNull(sink, "Expected duplicate-options sink endpoint");
+
+ String uri = sink.getEndpointUri();
+ assertEquals(1, countOccurrences(uri, "retain-first="),
+ () -> "Expected only one retain-first option: " + uri);
+ assertTrue(uri.matches(".*retain-first=[^&]+.*"),
+ () -> "Expected a canonical retain-first option: " + uri);
+ assertFalse(uri.contains("retainFirst="),
+ () -> "The camelCase alias should not remain in the URI: "
+ uri);
+ }
+ }
+
+ @Test
+ void testSinkOptionsWithDynamicOutputOnly() throws Exception {
+ try (CamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("dynamic-sink")
+ .from("kamelet:source")
+ .toD("log:${header.destination}");
+
+ from("direct:trigger")
+
.kamelet("dynamic-sink?advancedOptions=true&pageSize=10");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException, but got: " +
exception);
+
+ assertTrue(
+ exceptionChainContains(exception,
+ "advancedOptions cannot be applied"),
+ () -> "Expected a clear explanation for dynamic endpoints,
but got: " + exception);
+ }
+ }
+
+ @Test
+ void testSinkOptionsWithFixedAndDynamicOutputs() throws Exception {
+ try (CamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("mixed-sink")
+ .from("kamelet:source")
+ .to("mock:fixed-sink?retain-first=0")
+ .toD("mock:${header.destination}");
+
+ from("direct:trigger")
+
.kamelet("mixed-sink?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException for mixed
static/dynamic destinations, but got: "
+ + exception);
+ assertTrue(exceptionChainContains(exception, "contains a dynamic
destination"),
+ () -> "Expected a clear dynamic-destination error, but
got: " + exception);
+ }
+ }
+
+ @Test
+ void testSinkOptionsWithEnrichOnly() throws Exception {
+ assertDynamicSinkOptionsRejected("enrich", "enrich");
+ }
+
+ @Test
+ void testSinkOptionsWithPollEnrichOnly() throws Exception {
+ assertDynamicSinkOptionsRejected("pollEnrich", "pollEnrich");
+ }
+
+ @Test
+ void wireTapIsNotTreatedAsTheMainSinkDestination() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("wiretap-sink")
+ .from("kamelet:source")
+ .wireTap("mock:side-effect")
+ .to("mock:main-sink?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("wiretap-sink?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute =
findExpandedRouteWithOutput(testContext, "mock:main-sink");
+ ToDefinition mainSink = findToDefinition(expandedRoute,
"mock:main-sink");
+
+ assertNotNull(mainSink, "Expected main sink endpoint");
+ assertTrue(mainSink.getEndpointUri().contains("retain-first=1"),
+ () -> "Expected advanced option on main sink: " +
mainSink.getEndpointUri());
+
+ boolean wireTapHasAdvancedOption =
expandedRoute.getOutputs().stream()
+ .filter(output ->
output.getClass().getSimpleName().contains("WireTap"))
+ .anyMatch(output ->
output.toString().contains("retain-first=1"));
+
+ assertFalse(wireTapHasAdvancedOption,
+ "The wireTap destination should not receive sink options");
+ }
+ }
+
+ @Test
+ void testDynamicOutputWithoutSinkOptions() throws Exception {
+ try (CamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("dynamic-sink")
+ .from("kamelet:source")
+ .toD("mock:${header.destination}");
+
+ from("direct:trigger")
+ .kamelet("dynamic-sink");
+ }
+ });
+
+ testContext.start();
+
+ MockEndpoint dynamicSink =
testContext.getEndpoint("mock:dynamic-sink", MockEndpoint.class);
+ dynamicSink.expectedBodiesReceived("hello");
+
+ testContext.createProducerTemplate().sendBodyAndHeader(
+ "direct:trigger", "hello", "destination", "dynamic-sink");
+
+ dynamicSink.assertIsSatisfied();
+ }
+ }
+
+ @Test
+ void routeScopedPropertyDoesNotClashWithAdvancedOptions() throws Exception
{
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-template")
+ .from("kamelet:source")
+ .to("mock:result?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("sink-template/testRoute?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Properties properties = new Properties();
+ // This is a route-scoped property that should NOT be treated as
an advanced option
+
properties.put("camel.kamelet.sink-template.testRoute.source.retainFirst",
"999");
+
testContext.getPropertiesComponent().setInitialProperties(properties);
+ testContext.start();
+
+ RouteDefinition expandedRoute =
findExpandedRouteWithOutput(testContext, "mock:result");
+ ToDefinition sink = findToDefinition(expandedRoute, "mock:result");
+
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("retain-first=1"),
+ () -> "Expected URI parameter retain-first=1 from advanced
option: " + uri);
+ assertFalse(uri.contains("retain-first=999"),
+ () -> "Route-scoped property should not be treated as
advanced option: " + uri);
+ }
+ }
+
+ @Test
+ void routeScopedPropertyCannotInjectInternalPrefix() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-template")
+ .from("kamelet:source")
+ .to("mock:result?retain-first=0");
+
+ from("direct:trigger")
+ .kamelet("sink-template/testRoute");
+ }
+ });
+
+ Properties properties = new Properties();
+ // Attempt to inject via route-scoped property - should NOT work
+
properties.put("camel.kamelet.sink-template.testRoute.internal.advanced.options.retain-first",
"999");
+
testContext.getPropertiesComponent().setInitialProperties(properties);
+ testContext.start();
+
+ RouteDefinition expandedRoute =
findExpandedRouteWithOutput(testContext, "mock:result");
+ ToDefinition sink = findToDefinition(expandedRoute, "mock:result");
+
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ // The internal prefix should be ignored when coming from
route-scoped properties
+ assertFalse(uri.contains("retain-first=999"),
+ () -> "Route-scoped property with internal prefix should
be ignored: " + uri);
+ assertTrue(uri.contains("retain-first=0"),
+ () -> "Original value should remain: " + uri);
+ }
+ }
+
+ @Test
+ void removeQueryParameterPreservesRawAmpersands() {
+ String uri =
"kamelet:my-source?param=RAW(value&with&ersands)&other=123";
+
+ String result = Kamelet.removeQueryParameter(uri, "other");
+
+ assertEquals(
+ "kamelet:my-source?param=RAW(value&with&ersands)",
+ result);
+ }
+
+ @Test
+ void removeQueryParameterLeavesUriUnchangedWhenParameterIsAbsent() {
+ String uri = "http://host/path?filter=a%26b&keep=1";
+
+ String result = Kamelet.removeQueryParameter(uri, "pageSize");
+
+ assertEquals(uri, result);
+ }
+
+ @Test
+ void sinkOptionsRejectAmbiguousLogAndStaticDestinations() throws Exception
{
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("sink-with-log")
+ .from("kamelet:source")
+ .to("log:before-sink")
+ .to("mock:actual-sink?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("sink-with-log?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException for multiple
static destinations, but got: "
+ + exception);
+ assertTrue(exceptionChainContains(exception, "multiple top-level
static to() destinations"),
+ () -> "Expected a clear ambiguity error, but got: " +
exception);
+ }
+ }
+
+ @Test
+ void sinkOptionsPreserveOriginalCamelCaseSpelling() throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("spelling-sink")
+ .from("kamelet:source")
+ .to("http://localhost/unused-page-size");
+
+ from("direct:trigger")
+
.kamelet("spelling-sink?advancedOptions=true&pageSize=10");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute =
findExpandedRouteWithOutput(testContext, "http://localhost/unused-page-size");
+ ToDefinition sink = findToDefinition(expandedRoute,
"http://localhost/unused-page-size");
+
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.contains("pageSize=10"),
+ () -> "Expected original camelCase spelling to be
preserved: " + uri);
+ assertFalse(uri.contains("page-size="),
+ () -> "Parameter name must not be rewritten to kebab-case:
" + uri);
+
+ Map<String, Object> query = parseUriQuery(uri);
+ assertEquals("10", String.valueOf(query.get("pageSize")));
+ assertFalse(query.containsKey("page-size"),
+ () -> "Kebab-case alias must not be forwarded: " + query);
+ }
+ }
+
+ @Test
+ void sinkOptionsPreserveRawValuesWithUriSensitiveCharacters() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("password-sink")
+ .from("kamelet:source")
+ .to("http://localhost/unused-password");
+
+ from("direct:trigger")
+
.kamelet("password-sink?advancedOptions=true&password=RAW(p@ss&word)");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute =
findExpandedRouteWithOutput(testContext, "http://localhost/unused-password");
+ ToDefinition sink = findToDefinition(expandedRoute,
"http://localhost/unused-password");
+
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ Map<String, Object> query = parseUriQuery(uri);
+
+ assertEquals("p@ss&word", rawOrPlain(query.get("password")),
+ () -> "Expected the password value to remain intact: " +
uri);
+ assertFalse(query.containsKey("word"),
+ () -> "Ampersand in the password must not create a
spurious parameter: " + uri);
+
+ HttpEndpoint http = findHttpEndpoint(testContext,
"/unused-password");
+ assertNotNull(http, "Expected the HTTP sink endpoint to be
created");
+ String rawQuery = http.getHttpUri().getRawQuery();
+ assertNotNull(rawQuery, "Expected HTTP URI query parameters");
+ assertFalse(rawQuery.contains("&word"),
+ () -> "The HTTP endpoint must not receive a spurious word
parameter: " + http.getHttpUri());
+ Map<String, Object> httpQuery = URISupport.parseQuery(rawQuery);
+ assertEquals("p@ss&word",
urlDecode(rawOrPlain(httpQuery.get("password"))),
+ () -> "Expected the HTTP endpoint to receive the password
as one value: " + http.getHttpUri());
+ assertFalse(httpQuery.containsKey("word"),
+ () -> "The HTTP endpoint must not receive a spurious word
parameter: " + http.getHttpUri());
+ }
+ }
+
+ @Test
+ void advancedSinkOptionsSkipNestedKameletWhenSelectingMainSink() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("inner-sink")
+ .from("kamelet:source")
+ .to("mock:inner-sink");
+
+ routeTemplate("nested-and-main")
+ .from("kamelet:source")
+ .to("kamelet:inner-sink")
+ .to("mock:main-sink?retain-first=0");
+
+ from("direct:trigger")
+
.kamelet("nested-and-main?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute =
findExpandedRouteWithOutput(testContext, "mock:main-sink");
+ ToDefinition mainSink = findToDefinition(expandedRoute,
"mock:main-sink");
+ ToDefinition nested = findToDefinition(expandedRoute,
"kamelet:inner-sink");
+
+ assertNotNull(mainSink, "Expected main sink endpoint");
+ assertTrue(mainSink.getEndpointUri().contains("retain-first=1"),
+ () -> "Expected advanced option on the non-Kamelet sink: "
+ mainSink.getEndpointUri());
+
+ assertNotNull(nested, "Expected nested Kamelet destination");
+ assertFalse(nested.getEndpointUri().contains("retain-first="),
+ () -> "Nested kamelet: destination must not receive sink
options: " + nested.getEndpointUri());
+ }
+ }
+
+ @Test
+ void advancedSinkOptionsRejectNestedKameletOnlyDestinations() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("inner-sink")
+ .from("kamelet:source")
+ .to("mock:inner-sink");
+
+ routeTemplate("nested-kamelet-sink")
+ .from("kamelet:source")
+ .to("kamelet:inner-sink");
+
+ from("direct:trigger")
+
.kamelet("nested-kamelet-sink?advancedOptions=true&retain-first=1");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException, but got: " +
exception);
+ assertTrue(exceptionChainContains(exception, "no top-level static
to() destination"),
+ () -> "Expected no-static-sink error, but got: " +
exception);
+ }
+ }
+
+ @Test
+ void sinkOptionsPreservePercentEncodedSecretThroughRouteTemplate() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("percent-password-sink")
+ .from("kamelet:source")
+ .to("http://localhost/unused-percent-secret");
+
+ from("direct:trigger")
+
.kamelet("percent-password-sink?advancedOptions=true&password=RAW(se+cret%41)");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute = findExpandedRouteWithOutput(
+ testContext, "http://localhost/unused-percent-secret");
+ ToDefinition sink = findToDefinition(expandedRoute,
"http://localhost/unused-percent-secret");
+
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ Map<String, Object> query = parseUriQuery(uri);
+ String password = rawOrPlain(query.get("password"));
+
+ assertEquals("se+cret%41", password,
+ () -> "Expected the original literal password to remain
intact: " + uri);
+ assertNotEquals("se cretA", password,
+ () -> "+ and % must not be URI-decoded: " + uri);
+ assertNotEquals("se cret", password,
+ () -> "+ must not be decoded as a space: " + uri);
+ assertNotEquals("secretA", password,
+ () -> "%41 must not be decoded as A: " + uri);
+
+ HttpEndpoint http = findHttpEndpoint(testContext,
"/unused-percent-secret");
+ assertNotNull(http, "Expected the HTTP sink endpoint to be
created");
+ String rawQuery = http.getHttpUri().getRawQuery();
+ assertNotNull(rawQuery, "Expected HTTP URI query parameters");
+ Map<String, Object> httpQuery = URISupport.parseQuery(rawQuery);
+ String httpPassword =
urlDecode(rawOrPlain(httpQuery.get("password")));
+ assertEquals("se+cret%41", httpPassword,
+ () -> "Expected the HTTP endpoint to receive the original
literal password: "
+ + http.getHttpUri());
+ assertNotEquals("se cretA", httpPassword,
+ () -> "+ and % must not be URI-decoded on the HTTP
endpoint: " + http.getHttpUri());
+ }
+ }
+
+ @Test
+ void sinkOptionsPreserveJsonRawValueWithoutPropertyPlaceholder() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("json-filter-sink")
+ .from("kamelet:source")
+ .to("http://localhost/unused-json-filter");
+
+ from("direct:trigger")
+
.kamelet("json-filter-sink?advancedOptions=true&filter=RAW({\"a\":\"b&c\"})");
+ }
+ });
+
+ testContext.start();
+
+ RouteDefinition expandedRoute = findExpandedRouteWithOutput(
+ testContext, "http://localhost/unused-json-filter");
+ ToDefinition sink = findToDefinition(expandedRoute,
"http://localhost/unused-json-filter");
+
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertFalse(uri.contains("RAW{{"),
+ () -> "JSON must not be wrapped as RAW{{...}} or it
becomes a property placeholder: "
+ + uri);
+ assertTrue(uri.contains("RAW("),
+ () -> "Expected RAW(...) wrapping for the JSON value: " +
uri);
+
+ Map<String, Object> query = parseUriQuery(uri);
+ assertEquals("{\"a\":\"b&c\"}", rawOrPlain(query.get("filter")),
+ () -> "Expected the JSON value to remain intact: " + uri);
+ assertFalse(query.containsKey("c\"}"),
+ () -> "Ampersand in the JSON must not create a spurious
parameter: " + uri);
+ }
+ }
+
+ @Test
+ void sinkOptionsPreserveUnquotedCloseParenAmpersand() throws Exception {
+ assertHttpSinkOption("/unused-unquoted-paren-amp",
"advancedOptions=true&password=RAW{p@ss)&word}", "password",
+ "p@ss)&word", "word)");
+ }
+
+ @Test
+ void sinkOptionsPreserveMultipleAmpersands() throws Exception {
+ assertHttpSinkOption("/unused-multi-amp",
"advancedOptions=true&password=RAW(a&b&c)", "password", "a&b&c", "b", "c");
+ }
+
+ @Test
+ void sinkOptionsPreservePlusEqualsAndQuestionMark() throws Exception {
+ assertHttpSinkOption("/unused-plus-eq-q",
"advancedOptions=true&filter=RAW(a+b=c?d)", "filter", "a+b=c?d",
+ new String[0]);
+ }
+
+ @Test
+ void sinkOptionsOverrideTheOnlyExistingParameterAsTheLastOption() throws
Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("log-override-sink")
+ .from("kamelet:source")
+ .to("log:override?showAll=false");
+
+ from("direct:trigger")
+
.kamelet("log-override-sink?advancedOptions=true&level=INFO&showAll=true");
+ }
+ });
+
+ testContext.start();
+
+ ToDefinition sink = findToDefinition(
+ findExpandedRouteWithOutput(testContext, "log:override"),
"log:override");
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ assertTrue(uri.startsWith("log:override?"), () -> "Expected ?
before the first option: " + uri);
+ Map<String, Object> query = parseUriQuery(uri);
+ assertEquals(2, query.size(), () -> uri);
+ assertEquals("INFO", query.get("level"), () -> uri);
+ assertEquals("true", query.get("showAll"), () -> uri);
+ }
+ }
+
+ @Test
+ void removeQueryParameterHandlesRawAmpersandSafely() {
+ String uri = "http://host?auth=RAW(user:pass&token)&timeout=30";
+
+ // Test removing the parameter after the RAW value
+ String resultAfter = Kamelet.removeQueryParameter(uri, "timeout");
+ assertEquals("http://host?auth=RAW(user:pass&token)", resultAfter);
+
+ // Test removing the RAW value parameter itself
+ String resultBefore = Kamelet.removeQueryParameter(uri, "auth");
+ assertEquals("http://host?timeout=30", resultBefore);
+ }
+
+ @Test
+ void removeQueryParameterSplitsTheQueryLikeCamel() {
+ // Camel ends a RAW( value at the first ")&", so password is "p(ss"
and other is a parameter of its own
+ String uri = "foo:bar?password=RAW(p(ss)&other=1";
+
+ assertEquals("foo:bar?password=RAW(p(ss)",
Kamelet.removeQueryParameter(uri, "other"));
+ assertEquals("foo:bar?other=1", Kamelet.removeQueryParameter(uri,
"password"));
+ }
+
+ @Test
+ void removeQueryParameterKeepsRepeatedAndEncodedValues() {
+ String uri = "http://host/path?tag=a&tag=b&filter=a%26b&timeout=30";
+
+ assertEquals("http://host/path?tag=a&tag=b&filter=a%26b",
Kamelet.removeQueryParameter(uri, "timeout"));
+ }
+
+ @Test
+ void sinkOptionsAreReceivedLikeOptionsOnTheEndpointItself() throws
Exception {
+ String options =
"filter=a%26b&name=caf%C3%A9&q=a+b&secret=RAW(p@ss&word%41)&tag=x&tag=y";
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ ProbeComponent probe = new ProbeComponent();
+ testContext.addComponent("probe", probe);
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("encoded-sink")
+ .from("kamelet:source")
+ .to("probe:via-kamelet");
+
+ from("direct:kamelet")
+ .kamelet("encoded-sink?advancedOptions=true&" +
options);
+ from("direct:endpoint")
+ .to("probe:direct?" + options);
+ }
+ });
+
+ testContext.start();
+
+ Map<String, Object> received = probe.received.get("via-kamelet");
+
+ assertNotNull(received, "Expected the probe endpoint wrapped by
the Kamelet");
+ assertEquals("caf\u00e9", received.get("name"));
+ assertEquals("a b", received.get("q"));
+ assertEquals("p@ss&word%41", received.get("secret"));
+ assertEquals(List.of("x", "y"), received.get("tag"));
+ // filter=a%26b is checked by comparing with the endpoint used
directly
+ assertEquals(probe.received.get("direct"), received,
+ "The wrapped endpoint must receive the options the same as
when they are set on it directly");
+ }
+ }
+
+ private void assertHttpSinkOption(
+ String path, String sinkQuery, String optionName, String
expectedValue, String... forbiddenKeys)
+ throws Exception {
+ String templateId = path.substring(1);
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate(templateId)
+ .from("kamelet:source")
+ .to("http://localhost" + path);
+
+ from("direct:trigger")
+ .kamelet(templateId + "?" + sinkQuery);
+ }
+ });
+
+ testContext.start();
+
+ ToDefinition sink = findToDefinition(
+ findExpandedRouteWithOutput(testContext,
"http://localhost" + path),
+ "http://localhost" + path);
+ assertNotNull(sink, "Expected sink endpoint");
+ String uri = sink.getEndpointUri();
+ Map<String, Object> query = parseUriQuery(uri);
+ assertEquals(expectedValue, rawOrPlain(query.get(optionName)),
+ () -> "Expected option " + optionName + " to remain
intact: " + uri);
+ for (String forbidden : forbiddenKeys) {
+ assertFalse(query.containsKey(forbidden),
+ () -> "Must not treat " + forbidden + " as a separate
parameter: " + uri);
+ }
+ }
+ }
+
+ private Map<String, Object> parseUriQuery(String uri) throws Exception {
+ String query = URISupport.extractQuery(uri);
+ assertNotNull(query, () -> "Expected a query string on URI: " + uri);
+ return URISupport.parseQuery(query);
+ }
+
+ private String urlDecode(String value) {
+ return URLDecoder.decode(value, StandardCharsets.UTF_8);
+ }
+
+ private String rawOrPlain(Object value) {
+ assertNotNull(value, "Expected a query parameter value");
+ String text = String.valueOf(value);
+ if (text.startsWith("RAW(") && text.endsWith(")")) {
+ return text.substring(4, text.length() - 1);
+ }
+ if (text.startsWith("RAW{") && text.endsWith("}")) {
+ return text.substring(4, text.length() - 1);
+ }
+ return text;
+ }
+
+ private HttpEndpoint findHttpEndpoint(CamelContext testContext, String
path) {
+ return testContext.getEndpoints().stream()
+ .filter(HttpEndpoint.class::isInstance)
+ .map(HttpEndpoint.class::cast)
+ .filter(endpoint -> endpoint.getHttpUri() != null
+ && endpoint.getHttpUri().getPath() != null
+ && endpoint.getHttpUri().getPath().contains(path))
+ .findFirst()
+ .orElse(null);
+ }
+
+ private void assertDynamicSinkOptionsRejected(String processor, String
description) throws Exception {
+ try (DefaultCamelContext testContext = new DefaultCamelContext()) {
+ testContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ if ("enrich".equals(processor)) {
+ routeTemplate("dynamic-enricher")
+ .from("kamelet:source")
+ .enrich("mock:enrich-destination");
+ } else if ("pollEnrich".equals(processor)) {
+ routeTemplate("dynamic-enricher")
+ .from("kamelet:source")
+ .pollEnrich("mock:poll-enrich-destination");
+ } else if ("toD".equals(processor)) {
+ routeTemplate("dynamic-sink")
+ .from("kamelet:source")
+ .toD("log:${header.destination}");
+ } else {
+ throw new IllegalArgumentException("Unsupported
processor: " + processor);
+ }
+
+ from("direct:trigger")
+
.kamelet("dynamic-enricher?advancedOptions=true&pageSize=10");
+ }
+ });
+
+ Exception exception = assertThrows(Exception.class,
testContext::start);
+ assertTrue(hasIllegalArgumentException(exception),
+ () -> "Expected an IllegalArgumentException for " +
description + ", but got: " + exception);
+ assertTrue(exceptionChainContains(exception,
+ "advancedOptions cannot be applied"),
+ () -> "Expected a clear explanation for " + description +
", but got: " + exception);
+ }
+ }
+
+ private RouteDefinition findExpandedRouteWithOutput(CamelContext
testContext, String uriPrefix) {
+ return ((ModelCamelContext) testContext).getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> findToDefinition(route, uriPrefix) != null)
+ .findFirst()
+ .orElseThrow(() -> new AssertionError("Expanded Kamelet route
not found for " + uriPrefix));
+ }
+
+ private ToDefinition findToDefinition(RouteDefinition route, String
uriPrefix) {
+ return findToDefinitionInOutputs(route, uriPrefix);
+ }
+
+ private ToDefinition findToDefinitionInOutputs(
+ ProcessorDefinition<?> parent, String uriPrefix) {
+ if (parent.getOutputs() == null) {
+ return null;
+ }
+
+ for (ProcessorDefinition<?> output : parent.getOutputs()) {
+ if (output instanceof ToDefinition) {
+ ToDefinition to = (ToDefinition) output;
+ if (to.getEndpointUri() != null &&
to.getEndpointUri().startsWith(uriPrefix)) {
+ return to;
+ }
+ }
+
+ ToDefinition nested = findToDefinitionInOutputs(output, uriPrefix);
+ if (nested != null) {
+ return nested;
+ }
+ }
+
+ return null;
+ }
+
+ private long countOccurrences(String value, String target) {
+ return Pattern.compile(Pattern.quote(target))
+ .matcher(value)
+ .results()
+ .count();
+ }
+
+ private boolean exceptionChainContains(Throwable exception, String text) {
+ Throwable current = exception;
+ while (current != null) {
+ if (current.getMessage() != null &&
current.getMessage().contains(text)) {
+ return true;
+ }
+ if (current.getCause() == current) {
+ break;
+ }
+ current = current.getCause();
+ }
+ return false;
+ }
+
+ private boolean hasIllegalArgumentException(Throwable exception) {
+ Throwable current = exception;
+ while (current != null) {
+ if (current instanceof IllegalArgumentException) {
+ return true;
+ }
+ if (current.getCause() == current) {
+ break;
+ }
+ current = current.getCause();
+ }
+ return false;
+ }
+
+ private String findExpandedInputUri(String prefix) {
+ String uri = context.getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> route.getInput() != null)
+ .map(route -> route.getInput().getEndpointUri())
+ .filter(endpointUri -> endpointUri != null)
+ .filter(endpointUri -> endpointUri.startsWith(prefix))
+ .findFirst()
+ .orElse(null);
+
+ assertNotNull(uri, () -> {
+ String available = context.getRouteDefinitions().stream()
+ .filter(route -> Boolean.TRUE.equals(route.isKamelet()))
+ .filter(route -> route.getInput() != null)
+ .map(route -> route.getId() + " -> " +
route.getInput().getEndpointUri())
+ .collect(java.util.stream.Collectors.joining(", "));
+ return "No expanded Kamelet route input found with prefix " +
prefix
+ + ". Available Kamelet inputs: " + available;
+ });
+ return uri;
+ }
+
+ private RouteDefinition getRoute(String routeId) {
+ return context.getRouteDefinitions().stream()
+ .filter(route -> routeId.equals(route.getId()))
+ .findFirst()
+ .orElse(null);
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("direct-source")
+ .from("direct:source?synchronous=false")
+ .to("kamelet:sink");
+
+ routeTemplate("direct-source-with-options")
+ .from("direct:source-with-options?synchronous=false")
+ .to("kamelet:sink");
+
+ from("direct:source-trigger")
+ .routeId("sourceTrigger")
+
.to("kamelet:direct-source/sourceTest?advancedOptions=true&synchronous=true");
+
+ from("direct:source-override-trigger")
+ .routeId("sourceOverrideTrigger")
+
.to("kamelet:direct-source-with-options/sourceOverride?advancedOptions=true&synchronous=true");
+
+ routeTemplate("mock-sink-with-options")
+ .from("kamelet:source")
+ .to("mock:advanced-sink-result?retain-first=0");
+
+ from("direct:sink-trigger")
+ .routeId("sinkTrigger")
+
.kamelet("mock-sink-with-options?advancedOptions=true&retain-first=1&retain-last=5");
+
+ routeTemplate("mock-sink")
+ .from("kamelet:source")
+ .to("mock:basic-sink-result");
+
+ from("direct:basic-trigger")
+ .routeId("basicTrigger")
+ .kamelet("mock-sink");
+ }
+ };
+ }
+
+ private static final class ProbeComponent extends MockComponent {
+ private final Map<String, Map<String, Object>> received = new
ConcurrentHashMap<>();
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) {
+ // record the options as the component receives them, then accept
them all
+ received.put(remaining, new LinkedHashMap<>(parameters));
+ parameters.clear();
+ return new MockEndpoint(uri, this);
+ }
+ }
+}
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KameletComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KameletComponentBuilderFactory.java
index c2df77bea303..3f1f4ca2cb31 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KameletComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/KameletComponentBuilderFactory.java
@@ -190,6 +190,26 @@ public interface KameletComponentBuilderFactory {
}
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by
+ * the Kamelet. When enabled, parameters that are not Kamelet template
+ * properties or reserved Kamelet options are appended to the wrapped
+ * source or sink endpoint. Disabled by default.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: advanced
+ *
+ * @param advancedOptions the value to set
+ * @return the dsl builder
+ */
+ default KameletComponentBuilder advancedOptions(boolean
advancedOptions) {
+ doSetProperty("advancedOptions", advancedOptions);
+ return this;
+ }
+
+
/**
* Whether autowiring is enabled. This is used for automatic autowiring
* options (the option must be marked as autowired) by looking up in
the
@@ -273,6 +293,7 @@ public interface KameletComponentBuilderFactory {
case "block": ((KameletComponent) component).setBlock((boolean)
value); return true;
case "lazyStartProducer": ((KameletComponent)
component).setLazyStartProducer((boolean) value); return true;
case "timeout": ((KameletComponent) component).setTimeout((long)
value); return true;
+ case "advancedOptions": ((KameletComponent)
component).setAdvancedOptions((boolean) value); return true;
case "autowiredEnabled": ((KameletComponent)
component).setAutowiredEnabled((boolean) value); return true;
case "noErrorHandler": ((KameletComponent)
component).setNoErrorHandler((boolean) value); return true;
case "routeTemplateLoaderListener": ((KameletComponent)
component).setRouteTemplateLoaderListener((org.apache.camel.spi.RouteTemplateLoaderListener)
value); return true;
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KameletEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KameletEndpointBuilderFactory.java
index c0782f879296..e2668eca76b6 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KameletEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KameletEndpointBuilderFactory.java
@@ -171,6 +171,42 @@ public interface KameletEndpointBuilderFactory {
doSetProperty("exchangePattern", exchangePattern);
return this;
}
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by
+ * the Kamelet. When enabled, parameters that are not Kamelet template
+ * properties or reserved Kamelet options are appended to the wrapped
+ * source or sink endpoint. Disabled by default.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: advanced
+ *
+ * @param advancedOptions the value to set
+ * @return the dsl builder
+ */
+ default AdvancedKameletEndpointConsumerBuilder advancedOptions(boolean
advancedOptions) {
+ doSetProperty("advancedOptions", advancedOptions);
+ return this;
+ }
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by
+ * the Kamelet. When enabled, parameters that are not Kamelet template
+ * properties or reserved Kamelet options are appended to the wrapped
+ * source or sink endpoint. Disabled by default.
+ *
+ * The option will be converted to a <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: advanced
+ *
+ * @param advancedOptions the value to set
+ * @return the dsl builder
+ */
+ default AdvancedKameletEndpointConsumerBuilder advancedOptions(String
advancedOptions) {
+ doSetProperty("advancedOptions", advancedOptions);
+ return this;
+ }
/**
* Location of the Kamelet to use which can be specified as a resource
* from file system, classpath etc. The location cannot use wildcards,
@@ -396,6 +432,42 @@ public interface KameletEndpointBuilderFactory {
doSetProperty("timeout", timeout);
return this;
}
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by
+ * the Kamelet. When enabled, parameters that are not Kamelet template
+ * properties or reserved Kamelet options are appended to the wrapped
+ * source or sink endpoint. Disabled by default.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: advanced
+ *
+ * @param advancedOptions the value to set
+ * @return the dsl builder
+ */
+ default AdvancedKameletEndpointProducerBuilder advancedOptions(boolean
advancedOptions) {
+ doSetProperty("advancedOptions", advancedOptions);
+ return this;
+ }
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by
+ * the Kamelet. When enabled, parameters that are not Kamelet template
+ * properties or reserved Kamelet options are appended to the wrapped
+ * source or sink endpoint. Disabled by default.
+ *
+ * The option will be converted to a <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: advanced
+ *
+ * @param advancedOptions the value to set
+ * @return the dsl builder
+ */
+ default AdvancedKameletEndpointProducerBuilder advancedOptions(String
advancedOptions) {
+ doSetProperty("advancedOptions", advancedOptions);
+ return this;
+ }
/**
* Location of the Kamelet to use which can be specified as a resource
* from file system, classpath etc. The location cannot use wildcards,
@@ -483,6 +555,42 @@ public interface KameletEndpointBuilderFactory {
return (KameletEndpointBuilder) this;
}
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by
+ * the Kamelet. When enabled, parameters that are not Kamelet template
+ * properties or reserved Kamelet options are appended to the wrapped
+ * source or sink endpoint. Disabled by default.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: advanced
+ *
+ * @param advancedOptions the value to set
+ * @return the dsl builder
+ */
+ default AdvancedKameletEndpointBuilder advancedOptions(boolean
advancedOptions) {
+ doSetProperty("advancedOptions", advancedOptions);
+ return this;
+ }
+ /**
+ * Whether to forward extra URI parameters to the endpoint wrapped by
+ * the Kamelet. When enabled, parameters that are not Kamelet template
+ * properties or reserved Kamelet options are appended to the wrapped
+ * source or sink endpoint. Disabled by default.
+ *
+ * The option will be converted to a <code>boolean</code> type.
+ *
+ * Default: false
+ * Group: advanced
+ *
+ * @param advancedOptions the value to set
+ * @return the dsl builder
+ */
+ default AdvancedKameletEndpointBuilder advancedOptions(String
advancedOptions) {
+ doSetProperty("advancedOptions", advancedOptions);
+ return this;
+ }
/**
* Location of the Kamelet to use which can be specified as a resource
* from file system, classpath etc. The location cannot use wildcards,