gnodet commented on code in PR #27686:
URL: https://github.com/apache/camel/pull/27686#discussion_r4241899896
##########
components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java:
##########
@@ -62,6 +65,17 @@ 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.equals("kamelet://" + endpoint)
+ || uri.startsWith("kamelet://" + endpoint + "?");
Review Comment:
🔴 **Missing path-segment variants**: The original
`startsWith("kamelet:source")` matched URIs like `kamelet:source/routeId`. This
new method misses those — consider adding `startsWith(endpoint + "/")` checks
for both URI schemes.
```suggestion
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 + "/");
```
##########
components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java:
##########
@@ -230,9 +244,71 @@ public static RouteDefinition
templateToRoute(RouteTemplateDefinition in, Map<St
throw new IllegalArgumentException("Camel route " + rid + " input
does not exist.");
}
+ // Extract advanced options for source/sink component endpoints
+ Map<String, Object> sourceOptions =
PropertiesHelper.extractProperties(parameters, "source.");
+ Map<String, Object> sinkOptions =
PropertiesHelper.extractProperties(parameters, "sink.");
+
+ // Determine Kamelet type: source Kamelets have real component as
input,
+ // sink/action Kamelets have kamelet:source as input and real
component in outputs
+ boolean isSourceKamelet =
!isKameletEndpoint(def.getInput().getEndpointUri(), SOURCE_ID);
+
+ if (isSourceKamelet) {
+ // Source Kamelet: real component endpoint is the input
+ if (!sourceOptions.isEmpty()) {
+ try {
+ String newUri =
URISupport.appendParametersToURI(def.getInput().getUri(), sourceOptions);
+ def.getInput().setUri(newUri);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "Failed to apply advanced source options to
endpoint URI: " + def.getInput().getUri(), e);
+ }
+ }
+ if (!sinkOptions.isEmpty()) {
+ throw new IllegalArgumentException(
+ "sink.* advanced options are not valid for source
Kamelets (input is '"
+ +
def.getInput().getEndpointUri() + "'). Use source.* options instead.");
+ }
+ } else {
+ // Sink/Action Kamelet: real component endpoint(s) are in outputs
+ if (!sourceOptions.isEmpty()) {
+ throw new IllegalArgumentException(
+ "source.* advanced options are not valid for
sink/action Kamelets (input is '"
+ +
def.getInput().getEndpointUri() + "'). Use sink.* options instead.");
+ }
+ if (!sinkOptions.isEmpty()) {
+ Collection<ToDefinition> outputs =
filterTypeInOutputs(def.getOutputs(), ToDefinition.class);
+ boolean hasRealEndpoint = false;
+ for (ToDefinition to : outputs) {
+ String uri = to.getEndpointUri();
+ // Apply to all non-kamelet endpoints (real component
endpoints)
+ if (!uri.startsWith("kamelet:")) {
+ try {
+ String newUri =
URISupport.appendParametersToURI(uri, sinkOptions);
+ to.setUri(newUri);
+ hasRealEndpoint = true;
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "Failed to apply advanced sink options to
endpoint URI: " + uri, e);
+ }
+ }
+ }
+ if (!hasRealEndpoint) {
Review Comment:
🟡 **Silent skip when mixed `.to()` + `.toD()` outputs**: When
`hasRealEndpoint` is `true` (a static `to()` matched), this `if
(!hasRealEndpoint)` block never runs. Any `.toD()` endpoints are silently
skipped with no options applied and no diagnostic. If this is intentional
design, add a log warning so users can diagnose the mismatch.
##########
components/camel-kamelet/src/main/docs/kamelet-component.adoc:
##########
@@ -163,6 +163,46 @@ 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 pass these options
when using a Kamelet by prefixing them with `source.` or `sink.`, depending on
the type of Kamelet.
+
+==== Source Kamelets
+
+For source Kamelets, use the `source.` prefix to pass additional options to
the underlying source component endpoint. The prefix is removed when the
options are applied to the endpoint URI.
+
+For example:
+
+[source,java]
+----
+from("direct:start")
+ .to("kamelet:my-source/source?source.block=true");
+----
+
+The `/source` path segment is the route ID within the Kamelet template.
Replace `source` with the actual route ID defined in your Kamelet template.
+
+In this example, `source.block=true` passes `block=true` to the source
component endpoint. If the endpoint URI already contains the same option, the
advanced option overrides its existing value.
+
+==== Sink and action Kamelets
+
+For sink and action Kamelets, use the `sink.` prefix to pass additional
options to the component endpoints in the Kamelet output route. The prefix is
removed when the options are applied to the endpoint URIs.
+
+For example:
+
+[source,java]
+----
+from("direct:start")
+ .to("kamelet:my-sink/sink?sink.retain-first=1");
+----
+
+In this example, `sink.retain-first=1` passes `retain-first=1` to the
applicable output component endpoint. The options are applied to all
non-Kamelet output endpoints in the Kamelet route, so make sure the supplied
options are supported by each affected component.
Review Comment:
🟡 **Inaccurate doc**: "all non-Kamelet output endpoints" is misleading —
`.toD()` dynamic endpoints are not processed by this feature (only static
`to()` endpoints). Please clarify: e.g. _"applied to all statically-defined
non-Kamelet `to()` output endpoints"_.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]