You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/03/01 09:16:27 UTC

[camel-spring-boot] 01/02: CAMEL-14568: Use configurer for setting component options in SB auto configure

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-spring-boot.git

commit 361dfb13fac401ad13b906d0a195f1753c04def8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Mar 1 09:24:36 2020 +0100

    CAMEL-14568: Use configurer for setting component options in SB auto configure
---
 .../camel/spring/boot/util/CamelPropertiesHelper.java    | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/util/CamelPropertiesHelper.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/util/CamelPropertiesHelper.java
index f060a43..e732713 100644
--- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/util/CamelPropertiesHelper.java
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/util/CamelPropertiesHelper.java
@@ -20,8 +20,11 @@ import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
 import org.apache.camel.PropertyBindingException;
+import org.apache.camel.spi.PropertyConfigurer;
 import org.apache.camel.support.PropertyBindingSupport;
+import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -62,12 +65,20 @@ public final class CamelPropertiesHelper {
      * @throws IllegalArgumentException is thrown if an option cannot be configured on the bean because there is no suitable setter method and failOnNoSet is true.
      * @throws Exception for any other kind of error
      */
+    @Deprecated
     public static boolean setCamelProperties(CamelContext context, Object target, Map<String, Object> properties, boolean failIfNotSet) throws Exception {
         ObjectHelper.notNull(context, "context");
         ObjectHelper.notNull(target, "target");
         ObjectHelper.notNull(properties, "properties");
         boolean rc = false;
 
+        PropertyConfigurer configurer = null;
+        if (target instanceof Component) {
+            // the component needs to be initialized to have the configurer ready
+            ServiceHelper.initService(target);
+            configurer = ((Component) target).getComponentPropertyConfigurer();
+        }
+
         Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator();
         while (it.hasNext()) {
             Map.Entry<String, Object> entry = it.next();
@@ -76,7 +87,10 @@ public final class CamelPropertiesHelper {
             String stringValue = value != null ? value.toString() : null;
             boolean hit = false;
             try {
-                hit = PropertyBindingSupport.build().withIgnoreCase(true).bind(context, target, name, value);
+                hit = PropertyBindingSupport.build()
+                        .withConfigurer(configurer)
+                        .withIgnoreCase(true)
+                        .bind(context, target, name, value);
             } catch (PropertyBindingException e) {
                 // no we could not and this would be thrown if we attempted to set a value on a property which we cannot do type conversion as
                 // then maybe the value refers to a spring bean in the registry so try this