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

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


The following commit(s) were added to refs/heads/master by this push:
     new b0f2167  CAMEL-15565: camel-main beans configuration should lookup 
existing bean first.
b0f2167 is described below

commit b0f2167fb8a5b1a09d16595f2bd2b380e59fe14b
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Sep 22 09:19:39 2020 +0200

    CAMEL-15565: camel-main beans configuration should lookup existing bean 
first.
---
 .../org/apache/camel/main/BaseMainSupport.java     | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

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 48a96b0..ffc5350 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
@@ -35,6 +35,7 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
@@ -1190,6 +1191,9 @@ public abstract class BaseMainSupport extends BaseService 
{
 
         // make defensive copy as we mutate the map
         Set<String> keys = new LinkedHashSet<>(properties.keySet());
+        // find names of beans
+        final Set<String> beans
+                = properties.keySet().stream().map(k -> StringHelper.before(k, 
".", k)).collect(Collectors.toSet());
         // create beans first
         for (String key : keys) {
             if (key.indexOf('.') == -1) {
@@ -1205,22 +1209,17 @@ public abstract class BaseMainSupport extends 
BaseService {
                 camelContext.getRegistry().bind(name, bean);
             }
         }
-        // then set properties
-        for (String key : keys) {
-            if (key.indexOf('.') != -1) {
-                String name = StringHelper.before(key, ".");
-                String valueKey = StringHelper.after(key, ".");
-                Object value = properties.remove(key);
-                Object bean = camelContext.getRegistry().lookupByName(name);
-                if (bean == null) {
-                    throw new IllegalArgumentException(
-                            "Cannot resolve bean with name " + name);
-                }
-                Map<String, Object> map = new HashMap<>();
-                map.put(valueKey, value);
-                setPropertiesOnTarget(camelContext, bean, map, optionPrefix + 
name + ".", failIfNotSet, ignoreCase,
-                        autoConfiguredProperties);
+        // then set properties per bean
+        for (String name : beans) {
+            Object bean = camelContext.getRegistry().lookupByName(name);
+            if (bean == null) {
+                throw new IllegalArgumentException(
+                        "Cannot resolve bean with name " + name);
             }
+            // configure all the properties on the bean at once (to ensure 
they are configured in right order)
+            Map<String, Object> config = 
PropertiesHelper.extractProperties(properties, name + ".");
+            setPropertiesOnTarget(camelContext, bean, config, optionPrefix + 
name + ".", failIfNotSet, ignoreCase,
+                    autoConfiguredProperties);
         }
     }
 

Reply via email to