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

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

commit b4abddce191db7f4d4ce60ddb2b06023d4e28816
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Jun 22 09:38:35 2020 +0200

    CAMEL-15224: camel-api-component - Avoid reflection when configured nested 
configuration classes
---
 .../support/component/AbstractApiComponent.java     | 21 +++++++++++++++++++--
 .../component/ApiMethodPropertiesHelper.java        | 17 +++++++++++++----
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
index ae94410..93ece35 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
@@ -25,6 +25,8 @@ import org.apache.camel.CamelException;
 import org.apache.camel.Endpoint;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.PropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
 import org.apache.camel.support.DefaultComponent;
 import org.apache.camel.support.PropertyBindingSupport;
 
@@ -104,12 +106,27 @@ public abstract class AbstractApiComponent<E extends 
Enum<E> & ApiName, T, S ext
         final Map<String, Object> componentProperties = new HashMap<>();
         // copy component configuration, if set
         if (configuration != null) {
-            
getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getProperties(configuration,
 componentProperties, null, false);
+            PropertyConfigurer configurer = 
getCamelContext().adapt(ExtendedCamelContext.class).getConfigurerResolver().resolvePropertyConfigurer(configuration.getClass().getSimpleName(),
 getCamelContext());
+            // use reflection free configurer (if possible)
+            if (configurer instanceof PropertyConfigurerGetter) {
+                PropertyConfigurerGetter getter = (PropertyConfigurerGetter) 
configuration;
+                for (String key : 
getter.getAllOptions(configuration).keySet()) {
+                    Object value = getter.getOptionValue(configuration, key, 
true);
+                    if (value != null) {
+                        componentProperties.put(key, value);
+                    }
+                }
+            } else {
+                
getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getProperties(configuration,
 componentProperties, null, false);
+            }
         }
 
         // create endpoint configuration with component properties
         final T endpointConfiguration = 
collection.getEndpointConfiguration(name);
-        PropertyBindingSupport.build().bind(getCamelContext(), 
endpointConfiguration, componentProperties);
+        PropertyConfigurer configurer = 
getCamelContext().adapt(ExtendedCamelContext.class).getConfigurerResolver().resolvePropertyConfigurer(endpointConfiguration.getClass().getSimpleName(),
 getCamelContext());
+        PropertyBindingSupport.build()
+                .withConfigurer(configurer)
+                .bind(getCamelContext(), endpointConfiguration, 
componentProperties);
         return endpointConfiguration;
     }
 
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
index 0893303..36ec21d 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
@@ -26,6 +26,8 @@ import java.util.Set;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.spi.PropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -90,12 +92,19 @@ public abstract class ApiMethodPropertiesHelper<C> {
     }
 
     public void getEndpointProperties(CamelContext context, Object 
endpointConfiguration, Map<String, Object> properties) {
-        Set<String> names = null;
-        if 
(context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getProperties(endpointConfiguration,
 properties, null, false)) {
+        Set<String> names;
+
+        PropertyConfigurer configurer = 
context.adapt(ExtendedCamelContext.class).getConfigurerResolver().resolvePropertyConfigurer(endpointConfiguration.getClass().getSimpleName(),
 context);
+        // use reflection free configurer (if possible)
+        if (configurer instanceof PropertyConfigurerGetter) {
+            PropertyConfigurerGetter getter = (PropertyConfigurerGetter) 
endpointConfiguration;
+            names = getter.getAllOptions(endpointConfiguration).keySet();
+        } else {
+            
context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getProperties(endpointConfiguration,
 properties, null, false);
             names = properties.keySet();
-            // remove component config properties so we only have endpoint 
properties
-            names.removeAll(componentConfigFields);
         }
+        // remove component config properties so we only have endpoint 
properties
+        names.removeAll(componentConfigFields);
         LOG.debug("Found endpoint properties {}", names);
     }
 

Reply via email to