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

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


The following commit(s) were added to refs/heads/camel-3.20.x by this push:
     new a90591e05df CAMEL-18865: camel-main - Configuring options on beans dot 
vs square style. Dot style should use getter/setter and square should use 
map/list style first.
a90591e05df is described below

commit a90591e05df1e3f131af34ab750ad5b38fcf8af9
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jan 6 13:56:03 2023 +0100

    CAMEL-18865: camel-main - Configuring options on beans dot vs square style. 
Dot style should use getter/setter and square should use map/list style first.
---
 .../org/apache/camel/main/BaseMainSupport.java     |  2 +-
 .../java/org/apache/camel/main/MainBeansTest.java  | 26 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index e4ed47cc319..b5711dd9d03 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -1441,7 +1441,7 @@ public abstract class BaseMainSupport extends BaseService 
{
                         "Cannot resolve bean with name " + name);
             }
             // configure all the properties on the bean at once (to ensure 
they are configured in right order)
-            OrderedLocationProperties config = 
MainHelper.extractProperties(properties, name + "[", "]", true, (key) -> {
+            OrderedLocationProperties config = 
MainHelper.extractProperties(properties, name + "[", "]", true, key -> {
                 // when configuring map/list we want the keys to include the 
square brackets
                 // (so we know it is a map/list style and not dot style syntax)
                 // and therefore only remove the option prefix name
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java 
b/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java
index cb649abfccd..e734773bb81 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java
@@ -246,6 +246,32 @@ public class MainBeansTest {
         main.stop();
     }
 
+    @Test
+    public void testBindBeansDottedAndSquareHybridMap() {
+        Main main = new Main();
+        main.configure().addRoutesBuilder(new MyRouteBuilder());
+
+        // defining a factory bean
+        main.addProperty("camel.beans.myfactory", 
"#class:org.apache.camel.main.MyFooFactory");
+        main.addProperty("camel.beans.myfactory.hostName", "localhost");
+        main.addProperty("camel.beans.myfactory[region]", "emea");
+        main.start();
+
+        CamelContext camelContext = main.getCamelContext();
+        assertNotNull(camelContext);
+
+        Object bean = camelContext.getRegistry().lookupByName("myfactory");
+        assertNotNull(bean);
+        assertInstanceOf(MyFooFactory.class, bean);
+
+        MyFooFactory factory = (MyFooFactory) bean;
+        assertNull(factory.get("hostName"));
+        assertEquals("localhost", factory.getHostName());
+        assertEquals("emea", factory.get("region"));
+
+        main.stop();
+    }
+
     public static class MyRouteBuilder extends RouteBuilder {
         @Override
         public void configure() throws Exception {

Reply via email to