From 99c79464a86b0758222ed7d120f9419e2b48ed17 Mon Sep 17 00:00:00 2001 From: Tom Cunningham Date: Wed, 20 May 2026 21:54:02 -0400 Subject: [PATCH] CAMEL-23594: Fix property resolution issues in kamelet endpoint URIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two related fixes for property values used in kamelet endpoint URIs: 1. Trim whitespace from resolved property values in DefaultPropertiesParser. Property values containing trailing whitespace (e.g., from YAML literal block scalars using "|") cause URISyntaxException when resolved into endpoint URIs. The trim is safe since legitimate property values never depend on surrounding whitespace. 2. URL-decode kamelet endpoint parameters in KameletComponent. When YAML DSL creates kamelet URIs, it URL-encodes property values (e.g., "application/json" → "application%2Fjson"). Since KameletComponent uses useRawUri=true to preserve sensitive values, automatic URL-decoding is skipped. This fix manually decodes non-RAW parameter values so they are passed correctly to kamelet templates. Together these fixes resolve kamelet integration test failures where property values were either malformed (trailing newline causing URISyntaxException) or incorrectly encoded (Content-Type header sent as "application%2Fjson" instead of "application/json"). Co-Authored-By: Claude Sonnet 4.5 --- .../camel/component/kamelet/KameletComponent.java | 14 ++++++++++++++ .../properties/DefaultPropertiesParser.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) 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 241daa0248270..e612d186e20fa 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 @@ -16,6 +16,8 @@ */ package org.apache.camel.component.kamelet; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -132,6 +134,18 @@ protected Endpoint createEndpoint(String uri, String remaining, Map entry : parameters.entrySet()) { + if (entry.getValue() instanceof String s + && !s.startsWith(URISupport.RAW_TOKEN_PREFIX + "(") + && !s.startsWith(URISupport.RAW_TOKEN_PREFIX + "{")) { + entry.setValue(URLDecoder.decode(s, StandardCharsets.UTF_8)); + } + } + // manually need to resolve raw parameters as input to the kamelet because // resolveRawParameterValues is false // this ensures that parameters such as passwords are used as-is and not encoded diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java index 43edd497bb15e..8b78d19146e82 100644 --- a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java +++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java @@ -514,7 +514,7 @@ private String doGetPropertyValue(String key, String defaultValue) { if (answer == null) { answer = value; } - return answer; + return answer != null ? answer.trim() : null; } }