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 6979c761eea5 CAMEL-22978: camel-core - Property binding
constructor/factory-method should better match parameters for overloaded
methods. (#21390)
6979c761eea5 is described below
commit 6979c761eea569d460de3f98bb0f438cb4d9ec72
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Feb 10 19:14:17 2026 +0100
CAMEL-22978: camel-core - Property binding constructor/factory-method
should better match parameters for overloaded methods. (#21390)
---
...ndingSupportClassConstructorOverloadedTest.java | 133 ++++++++++++++++++++
...ingSupportClassFactoryMethodOverloadedTest.java | 137 +++++++++++++++++++++
.../camel/support/PropertyBindingSupport.java | 20 ++-
3 files changed, 284 insertions(+), 6 deletions(-)
diff --git
a/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportClassConstructorOverloadedTest.java
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportClassConstructorOverloadedTest.java
new file mode 100644
index 000000000000..94a49c34a751
--- /dev/null
+++
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportClassConstructorOverloadedTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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 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;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Unit test for PropertyBindingSupport
+ */
+public class PropertyBindingSupportClassConstructorOverloadedTest {
+
+ @Test
+ public void testConstructorOverloaded() {
+ CamelContext context = new DefaultCamelContext();
+
+ context.start();
+
+ MyApp target = new MyApp();
+
+ PropertyBindingSupport.build()
+ .withCamelContext(context)
+ .withTarget(target)
+ .withProperty("name", "Donald")
+ .withProperty("myBinding",
+ "#class:" + MyBinding.class.getName() +
"(true,'scott')")
+ .withRemoveParameters(false).bind();
+
+ assertEquals("Donald", target.getName());
+ assertTrue(target.getMyBinding().isFlag());
+ assertFalse(target.getMyBinding().isFlag2());
+ assertEquals("scott", target.getMyBinding().getUser());
+
+ context.stop();
+ }
+
+ @Test
+ public void testConstructorOverloadedTwo() {
+ CamelContext context = new DefaultCamelContext();
+
+ context.start();
+
+ MyApp target = new MyApp();
+
+ PropertyBindingSupport.build()
+ .withCamelContext(context)
+ .withTarget(target)
+ .withProperty("name", "Donald")
+ .withProperty("myBinding",
+ "#class:" + MyBinding.class.getName() + "(true,true)")
+ .withRemoveParameters(false).bind();
+
+ assertEquals("Donald", target.getName());
+ assertTrue(target.getMyBinding().isFlag());
+ assertTrue(target.getMyBinding().isFlag2());
+ assertEquals("anonymous", target.getMyBinding().getUser());
+
+ context.stop();
+ }
+
+ public static class MyApp {
+
+ private String name;
+ private MyBinding myBinding;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public MyBinding getMyBinding() {
+ return myBinding;
+ }
+
+ public void setMyBinding(MyBinding myBinding) {
+ this.myBinding = myBinding;
+ }
+ }
+
+ public static class MyBinding {
+
+ private boolean flag;
+ private boolean flag2;
+ private String user;
+
+ public MyBinding(boolean flag, boolean flag2) {
+ this.flag = flag;
+ this.flag2 = flag2;
+ this.user = "anonymous";
+ }
+
+ public MyBinding(boolean flag, String user) {
+ this.flag = flag;
+ this.user = user;
+ }
+
+ public boolean isFlag() {
+ return flag;
+ }
+
+ public boolean isFlag2() {
+ return flag2;
+ }
+
+ public String getUser() {
+ return user;
+ }
+ }
+
+}
diff --git
a/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportClassFactoryMethodOverloadedTest.java
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportClassFactoryMethodOverloadedTest.java
new file mode 100644
index 000000000000..d824d9a3b0b0
--- /dev/null
+++
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportClassFactoryMethodOverloadedTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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 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;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Unit test for PropertyBindingSupport
+ */
+public class PropertyBindingSupportClassFactoryMethodOverloadedTest {
+
+ @Test
+ public void testFactoryPropertyOverloaded() {
+ CamelContext context = new DefaultCamelContext();
+
+ context.start();
+
+ MyApp target = new MyApp();
+
+ PropertyBindingSupport.build()
+ .withCamelContext(context)
+ .withTarget(target)
+ .withProperty("name", "Donald")
+ .withProperty("myBinding",
+ "#class:" + MyBinding.class.getName() +
"#createBinding(true,'scott')")
+ .withRemoveParameters(false).bind();
+
+ assertEquals("Donald", target.getName());
+ assertTrue(target.getMyBinding().isFlag());
+ assertFalse(target.getMyBinding().isFlag2());
+ assertEquals("scott", target.getMyBinding().getUser());
+
+ context.stop();
+ }
+
+ @Test
+ public void testFactoryPropertyOverloadedTwo() {
+ CamelContext context = new DefaultCamelContext();
+
+ context.start();
+
+ MyApp target = new MyApp();
+
+ PropertyBindingSupport.build()
+ .withCamelContext(context)
+ .withTarget(target)
+ .withProperty("name", "Donald")
+ .withProperty("myBinding",
+ "#class:" + MyBinding.class.getName() +
"#createBinding(true,true)")
+ .withRemoveParameters(false).bind();
+
+ assertEquals("Donald", target.getName());
+ assertTrue(target.getMyBinding().isFlag());
+ assertTrue(target.getMyBinding().isFlag2());
+ assertEquals("anonymous", target.getMyBinding().getUser());
+
+ context.stop();
+ }
+
+ public static class MyApp {
+
+ private String name;
+ private MyBinding myBinding;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public MyBinding getMyBinding() {
+ return myBinding;
+ }
+
+ public void setMyBinding(MyBinding myBinding) {
+ this.myBinding = myBinding;
+ }
+ }
+
+ public static class MyBinding {
+
+ private boolean flag;
+ private boolean flag2;
+ private String user;
+
+ public static MyBinding createBinding(boolean flag, String user) {
+ MyBinding binding = new MyBinding();
+ binding.flag = flag;
+ binding.user = user;
+ return binding;
+ }
+
+ public static MyBinding createBinding(boolean flag, boolean flag2) {
+ MyBinding binding = new MyBinding();
+ binding.flag = flag;
+ binding.flag2 = flag2;
+ binding.user = "anonymous";
+ return binding;
+ }
+
+ public boolean isFlag() {
+ return flag;
+ }
+
+ public boolean isFlag2() {
+ return flag2;
+ }
+
+ public String getUser() {
+ return user;
+ }
+ }
+
+}
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 bef39e9a43f6..3d8df6cced76 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
@@ -1251,7 +1251,8 @@ public final class PropertyBindingSupport {
*/
public static Object newInstanceConstructorParameters(CamelContext
camelContext, Class<?> type, String parameters)
throws Exception {
- String[] params = StringQuoteHelper.splitSafeQuote(parameters, ',');
+ // 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) {
Object[] arr = new Object[found.getParameterCount()];
@@ -1261,11 +1262,14 @@ 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) {
- if (str.startsWith("#")) {
- Object bean = resolveBean(camelContext, param);
+ String ref =
StringHelper.removeLeadingAndEndingQuotes(str);
+ if (ref.startsWith("#")) {
+ Object bean = resolveBean(camelContext, ref);
if (bean != null) {
val = bean;
}
+ } else {
+ val = str;
}
}
// unquote text
@@ -1351,7 +1355,8 @@ public final class PropertyBindingSupport {
public static Object newInstanceFactoryParameters(
CamelContext camelContext, Class<?> type, String factoryMethod,
String parameters)
throws Exception {
- String[] params = StringQuoteHelper.splitSafeQuote(parameters, ',');
+ // 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) {
Object[] arr = new Object[found.getParameterCount()];
@@ -1361,11 +1366,14 @@ 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) {
- if (str.startsWith("#")) {
- Object bean = resolveBean(camelContext, param);
+ String ref =
StringHelper.removeLeadingAndEndingQuotes(str);
+ if (ref.startsWith("#")) {
+ Object bean = resolveBean(camelContext, ref);
if (bean != null) {
val = bean;
}
+ } else {
+ val = str;
}
}
// unquote text