This is an automated email from the ASF dual-hosted git repository.

Croway pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new 52cf21cf0cb5 [camel-4.18.x] CAMEL-27110: camel-jbang - camel bind 
substitutes its templates literally, and BindTest expects the example value of 
the set-body-action Kamelet (#30280)
52cf21cf0cb5 is described below

commit 52cf21cf0cb5acfdad962911977fba8926dd7878
Author: Federico Mariani <[email protected]>
AuthorDate: Tue Nov 17 17:08:21 2026 +0100

    [camel-4.18.x] CAMEL-27110: camel-jbang - camel bind substitutes its 
templates literally, and BindTest expects the example value of the 
set-body-action Kamelet (#30280)
    
    * CAMEL-27110: camel-jbang - camel bind substitutes its templates 
literally, so a property value with ${...} no longer fails
    
    The bind templates were filled with replaceFirst, which reads the ${...} of 
a
    value as a regex group reference, so camel bind failed with "named capturing
    group is missing trailing '}'" for a property such as
    source.message=Order ${header.orderId} received, and for a Kamelet step 
whose
    example holds one (set-body-action on camel-kamelets main). They are now 
filled
    with String.replace, as on camel-4.22.x and main since 53b399d885e9 (its 
other
    changes are not taken).
    
    * CAMEL-27110: camel-jbang - BindTest expects the example value of the 
set-body-action Kamelet
    
    camel bind reads the Kamelets from the main branch of camel-kamelets, where
    set-body-action now has an example value, which bind uses for the step
    property.
---
 .../camel/dsl/jbang/core/commands/bind/Bind.java   | 16 +++++------
 .../bind/ObjectReferenceBindingProvider.java       | 10 +++----
 .../core/commands/bind/UriBindingProvider.java     |  4 +--
 .../dsl/jbang/core/commands/bind/BindTest.java     | 32 ++++++++++++++++++++--
 4 files changed, 45 insertions(+), 17 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/Bind.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/Bind.java
index 28ec26478785..fe239ac87d53 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/Bind.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/Bind.java
@@ -160,15 +160,15 @@ public class Bind extends CamelCommand {
                         is = templateProvider.getErrorHandlerTemplate("sink");
                         errorHandlerSpec = IOHelper.loadText(is);
                         IOHelper.close(is);
-                        errorHandlerSpec = 
errorHandlerSpec.replaceFirst("\\{\\{ \\.Endpoint }}", endpoint);
-                        errorHandlerSpec = 
errorHandlerSpec.replaceFirst("\\{\\{ \\.ErrorHandlerParameter }}",
+                        errorHandlerSpec = errorHandlerSpec.replace("{{ 
.Endpoint }}", endpoint);
+                        errorHandlerSpec = errorHandlerSpec.replace("{{ 
.ErrorHandlerParameter }}",
                                 
templateProvider.asErrorHandlerParameters(errorHandlerParameters));
                         break;
                     case "log":
                         is = templateProvider.getErrorHandlerTemplate("log");
                         errorHandlerSpec = IOHelper.loadText(is);
                         IOHelper.close(is);
-                        errorHandlerSpec = 
errorHandlerSpec.replaceFirst("\\{\\{ \\.ErrorHandlerParameter }}",
+                        errorHandlerSpec = errorHandlerSpec.replace("{{ 
.ErrorHandlerParameter }}",
                                 
templateProvider.asErrorHandlerParameters(errorHandlerParameters));
                         break;
                     default:
@@ -179,11 +179,11 @@ public class Bind extends CamelCommand {
             }
 
             String name = FileUtil.onlyName(file, false);
-            context = context.replaceFirst("\\{\\{ \\.Name }}", name);
-            context = context.replaceFirst("\\{\\{ \\.Source }}\n", 
sourceEndpoint);
-            context = context.replaceFirst("\\{\\{ \\.Sink }}\n", 
sinkEndpoint);
-            context = context.replaceFirst("\\{\\{ \\.Steps }}", stepsContext);
-            context = context.replaceFirst("\\{\\{ \\.ErrorHandler }}", 
errorHandlerContext);
+            context = context.replace("{{ .Name }}", name);
+            context = context.replace("{{ .Source }}\n", sourceEndpoint);
+            context = context.replace("{{ .Sink }}\n", sinkEndpoint);
+            context = context.replace("{{ .Steps }}", stepsContext);
+            context = context.replace("{{ .ErrorHandler }}", 
errorHandlerContext);
             return context;
         } catch (Exception e) {
             printer().printErr(e);
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/ObjectReferenceBindingProvider.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/ObjectReferenceBindingProvider.java
index f93db17eea85..268f8318993b 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/ObjectReferenceBindingProvider.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/ObjectReferenceBindingProvider.java
@@ -104,11 +104,11 @@ public class ObjectReferenceBindingProvider implements 
BindingProvider {
             namespaceContext = "      namespace: " + namespace + "\n";
         }
 
-        context = context.replaceFirst("\\{\\{ \\.ApiVersion }}", 
apiVersionValue);
-        context = context.replaceFirst("\\{\\{ \\.Kind }}", kindValue);
-        context = context.replaceFirst("\\{\\{ \\.Name }}", objectName);
-        context = context.replaceFirst("\\{\\{ \\.Namespace }}\n", 
namespaceContext);
-        context = context.replaceFirst("\\{\\{ \\.EndpointProperties }}\n",
+        context = context.replace("{{ .ApiVersion }}", apiVersionValue);
+        context = context.replace("{{ .Kind }}", kindValue);
+        context = context.replace("{{ .Name }}", objectName);
+        context = context.replace("{{ .Namespace }}\n", namespaceContext);
+        context = context.replace("{{ .EndpointProperties }}\n",
                 templateProvider.asEndpointProperties(endpointUriProperties));
 
         return context;
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/UriBindingProvider.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/UriBindingProvider.java
index 746952e6db54..1d236832b744 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/UriBindingProvider.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/bind/UriBindingProvider.java
@@ -56,8 +56,8 @@ public class UriBindingProvider implements BindingProvider {
         String context = IOHelper.loadText(is);
         IOHelper.close(is);
 
-        context = context.replaceFirst("\\{\\{ \\.URI }}", endpointUri);
-        context = context.replaceFirst("\\{\\{ \\.EndpointProperties }}\n",
+        context = context.replace("{{ .URI }}", endpointUri);
+        context = context.replace("{{ .EndpointProperties }}\n",
                 templateProvider.asEndpointProperties(endpointProperties));
 
         return context;
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/bind/BindTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/bind/BindTest.java
index 2097c88e7bb2..74f716f49576 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/bind/BindTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/bind/BindTest.java
@@ -220,7 +220,7 @@ class BindTest extends CamelCommandBaseTestSupport {
                       apiVersion: camel.apache.org/v1
                       name: set-body-action
                     properties:
-                      value: "value"
+                      value: "Order ${header.orderId} received"
                   - ref:
                       kind: Kamelet
                       apiVersion: camel.apache.org/v1
@@ -268,7 +268,7 @@ class BindTest extends CamelCommandBaseTestSupport {
                       apiVersion: camel.apache.org/v1
                       name: set-body-action
                     properties:
-                      value: "value"
+                      value: "Order ${header.orderId} received"
                   - uri: log:info
                     #properties:
                       #key: "value"
@@ -584,6 +584,34 @@ class BindTest extends CamelCommandBaseTestSupport {
                 """.trim(), output);
     }
 
+    @Test
+    public void shouldBindUriToUriWithPropertyHoldingAnExpression() throws 
Exception {
+        Bind command = createCommand("timer:tick", "log:info");
+
+        command.properties = new String[] {
+                "source.message=Order ${header.orderId} received",
+        };
+
+        command.doCall();
+
+        String output = printer.getOutput();
+        Assertions.assertEquals("""
+                apiVersion: camel.apache.org/v1
+                kind: Pipe
+                metadata:
+                  name: timer-to-log
+                spec:
+                  source:
+                    uri: timer:tick
+                    properties:
+                      message: Order ${header.orderId} received
+                  sink:
+                    uri: log:info
+                    #properties:
+                      #key: "value"
+                """.trim(), output);
+    }
+
     @Test
     public void shouldBindUriToUriWithUriProperties() throws Exception {
         Bind command = createCommand("timer:tick?period=10000", 
"log:info?showStreams=false");

Reply via email to