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 739edddc4942 CAMEL-22978: camel-core - Property binding 
constructor/factory-method should better match parameters for overloaded 
methods.
739edddc4942 is described below

commit 739edddc4942fc1661aea07453a5714115a5de99
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Feb 11 14:10:34 2026 +0100

    CAMEL-22978: camel-core - Property binding constructor/factory-method 
should better match parameters for overloaded methods.
---
 .../PropertyBindingSupportConstructorTest.java     | 101 +++++++++++++++++++++
 .../org/apache/camel/support/EndpointHelper.java   |   3 +
 .../camel/support/PropertyBindingSupport.java      |  32 +++++--
 3 files changed, 130 insertions(+), 6 deletions(-)

diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportConstructorTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportConstructorTest.java
new file mode 100644
index 000000000000..c40664de85d0
--- /dev/null
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportConstructorTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.main;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.PropertyBindingSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Unit test for PropertyBindingSupport
+ */
+public class PropertyBindingSupportConstructorTest {
+
+    @Test
+    public void testConstructor() {
+        CamelContext context = new DefaultCamelContext();
+
+        context.start();
+
+        MyApp target = new MyApp();
+
+        PropertyBindingSupport.build()
+                .withCamelContext(context)
+                .withTarget(target)
+                .withProperty("name", "Donald")
+                .withProperty("counter",
+                        "#class:" + AtomicInteger.class.getName() + "(1)")
+                .withRemoveParameters(false).bind();
+
+        assertEquals("Donald", target.getName());
+        assertEquals(1, target.getCounter().get());
+
+        context.stop();
+    }
+
+    @Test
+    public void testConstructorPlaceholder() {
+        CamelContext context = new DefaultCamelContext();
+
+        context.getPropertiesComponent().addInitialProperty("initVal", "123");
+
+        context.start();
+
+        MyApp target = new MyApp();
+
+        PropertyBindingSupport.build()
+                .withCamelContext(context)
+                .withTarget(target)
+                .withProperty("name", "Donald")
+                .withProperty("counter",
+                        "#class:" + AtomicInteger.class.getName() + 
"({{initVal}})")
+                .withRemoveParameters(false).bind();
+
+        assertEquals("Donald", target.getName());
+        assertEquals(123, target.getCounter().get());
+
+        context.stop();
+    }
+
+    public static class MyApp {
+
+        private String name;
+        private AtomicInteger counter;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public AtomicInteger getCounter() {
+            return counter;
+        }
+
+        public void setCounter(AtomicInteger counter) {
+            this.counter = counter;
+        }
+    }
+
+}
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java 
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index ba45fa75279a..e061826597a8 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -405,6 +405,9 @@ public final class EndpointHelper {
             parameters = StringHelper.after(className, "(");
             parameters = parameters.substring(0, parameters.length() - 1); // 
clip last )
             className = StringHelper.before(className, "(");
+            if (parameters.isBlank()) {
+                parameters = null;
+            }
         }
         if (className != null && className.indexOf('#') != -1) {
             factoryMethod = StringHelper.after(className, "#");
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 3d8df6cced76..18e6e1463209 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -48,6 +48,7 @@ import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.StringQuoteHelper;
 
 import static org.apache.camel.util.ObjectHelper.isNotEmpty;
+import static org.apache.camel.util.StringHelper.removeLeadingAndEndingQuotes;
 import static org.apache.camel.util.StringHelper.startsWithIgnoreCase;
 
 /**
@@ -334,7 +335,7 @@ public final class PropertyBindingSupport {
         boolean quoted = StringHelper.isQuoted(name);
         if (quoted) {
             // remove quotes around the key
-            name = StringHelper.removeLeadingAndEndingQuotes(name);
+            name = removeLeadingAndEndingQuotes(name);
             newName = name;
             parts = new String[] { name };
         } else if (isDotKey(name)) {
@@ -612,7 +613,7 @@ public final class PropertyBindingSupport {
 
         int pos = name.indexOf('[');
         String lookupKey = name.substring(pos + 1, name.length() - 1);
-        lookupKey = StringHelper.removeLeadingAndEndingQuotes(lookupKey);
+        lookupKey = removeLeadingAndEndingQuotes(lookupKey);
         String key = name.substring(0, pos);
 
         Object obj = null;
@@ -703,7 +704,7 @@ public final class PropertyBindingSupport {
 
         int pos = name.indexOf('[');
         String lookupKey = name.substring(pos + 1, name.length() - 1);
-        lookupKey = StringHelper.removeLeadingAndEndingQuotes(lookupKey);
+        lookupKey = removeLeadingAndEndingQuotes(lookupKey);
         String key = name.substring(0, pos);
         String undashKey = undashKey(key);
 
@@ -1254,6 +1255,14 @@ public final class PropertyBindingSupport {
         // keep quotes as we need to understand the parameter type if its 
boolean,numbers or string (quoted)
         String[] params = StringQuoteHelper.splitSafeQuote(parameters, ',', 
true, true);
         Constructor<?> found = findMatchingConstructor(camelContext, 
type.getConstructors(), params);
+        if (found == null) {
+            // fallback with unquoted parameters as some may have been using 
property placeholders to inject their values
+            String[] params2 = new String[params.length];
+            for (int i = 0; i < params.length; i++) {
+                params2[i] = 
StringHelper.removeLeadingAndEndingQuotes(params[i]);
+            }
+            found = findMatchingConstructor(camelContext, 
type.getConstructors(), params2);
+        }
         if (found != null) {
             Object[] arr = new Object[found.getParameterCount()];
             for (int i = 0; i < found.getParameterCount(); i++) {
@@ -1274,7 +1283,7 @@ public final class PropertyBindingSupport {
                 }
                 // unquote text
                 if (val instanceof String strVal) {
-                    val = StringHelper.removeLeadingAndEndingQuotes(strVal);
+                    val = removeLeadingAndEndingQuotes(strVal);
                 }
                 if (val != null) {
                     val = 
camelContext.getTypeConverter().tryConvertTo(paramType, val);
@@ -1358,6 +1367,14 @@ public final class PropertyBindingSupport {
         // keep quotes as we need to understand the parameter type if its 
boolean,numbers or string (quoted)
         String[] params = StringQuoteHelper.splitSafeQuote(parameters, ',', 
true, true);
         Method found = findMatchingFactoryMethod(camelContext, 
type.getMethods(), factoryMethod, params);
+        if (found == null) {
+            // fallback with unquoted parameters as some may have been using 
property placeholders to inject their values
+            String[] params2 = new String[params.length];
+            for (int i = 0; i < params.length; i++) {
+                params2[i] = 
StringHelper.removeLeadingAndEndingQuotes(params[i]);
+            }
+            found = findMatchingFactoryMethod(camelContext, type.getMethods(), 
factoryMethod, params2);
+        }
         if (found != null) {
             Object[] arr = new Object[found.getParameterCount()];
             for (int i = 0; i < found.getParameterCount(); i++) {
@@ -1366,7 +1383,7 @@ public final class PropertyBindingSupport {
                 Object val = null;
                 // special as we may refer to other #bean or #type in the 
parameter
                 if (param instanceof String str) {
-                    String ref = 
StringHelper.removeLeadingAndEndingQuotes(str);
+                    String ref = removeLeadingAndEndingQuotes(str);
                     if (ref.startsWith("#")) {
                         Object bean = resolveBean(camelContext, ref);
                         if (bean != null) {
@@ -1378,7 +1395,7 @@ public final class PropertyBindingSupport {
                 }
                 // unquote text
                 if (val instanceof String strVal) {
-                    val = StringHelper.removeLeadingAndEndingQuotes(strVal);
+                    val = removeLeadingAndEndingQuotes(strVal);
                 }
                 if (val != null) {
                     val = 
camelContext.getTypeConverter().tryConvertTo(paramType, val);
@@ -1579,6 +1596,9 @@ public final class PropertyBindingSupport {
                 parameters = StringHelper.after(className, "(");
                 parameters = parameters.substring(0, parameters.length() - 1); 
// clip last )
                 className = StringHelper.before(className, "(");
+                if (parameters.isBlank()) {
+                    parameters = null;
+                }
             }
             if (className != null && className.indexOf('#') != -1) {
                 factoryMethod = StringHelper.after(className, "#");

Reply via email to