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/12/05 14:10:03 UTC

[camel] branch master updated (8e45bd8 -> 4899ea9)

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

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


    from 8e45bd8  Regen for commit c1e0ae6f25a2f0a2763a3f981818b73bbefb557c
     new a177812  CAMEL-15764: Setting properties via configurer should ignore case by default as end users may use mixed case and the API components rely on parameter names with a specific case
     new 4899ea9  CAMEL-15764: api component should not use reflection when configuring their endpoints.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/twilio/TwilioEndpointTest.java | 48 +++++++++-------------
 .../reifier/dataformat/DataFormatReifier.java      |  1 +
 .../camel/reifier/language/ExpressionReifier.java  |  1 +
 .../org/apache/camel/support/DefaultComponent.java |  4 +-
 .../org/apache/camel/support/DefaultEndpoint.java  |  4 +-
 .../camel/support/RestProducerFactoryHelper.java   |  2 +-
 .../support/component/AbstractApiComponent.java    |  1 +
 .../support/component/AbstractApiEndpoint.java     | 34 ++++++++++++++-
 8 files changed, 60 insertions(+), 35 deletions(-)
 copy core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointWithParametersTest.java => components/camel-twilio/src/test/java/org/apache/camel/component/twilio/TwilioEndpointTest.java (50%)


[camel] 01/02: CAMEL-15764: Setting properties via configurer should ignore case by default as end users may use mixed case and the API components rely on parameter names with a specific case

Posted by da...@apache.org.
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

commit a177812a5486affd534bba9006f0f1fd4be7afbc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Dec 5 13:14:46 2020 +0100

    CAMEL-15764: Setting properties via configurer should ignore case by default as end users may use mixed case and the API components rely on parameter names with a specific case
---
 .../java/org/apache/camel/reifier/dataformat/DataFormatReifier.java   | 1 +
 .../java/org/apache/camel/reifier/language/ExpressionReifier.java     | 1 +
 .../src/main/java/org/apache/camel/support/DefaultComponent.java      | 4 ++--
 .../src/main/java/org/apache/camel/support/DefaultEndpoint.java       | 4 ++--
 .../main/java/org/apache/camel/support/RestProducerFactoryHelper.java | 2 +-
 .../java/org/apache/camel/support/component/AbstractApiComponent.java | 1 +
 6 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
index e51fe35..f3e5dd4 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
@@ -317,6 +317,7 @@ public abstract class DataFormatReifier<T extends DataFormatDefinition> extends
                 .withTarget(dataFormat)
                 .withReference(true)
                 .withMandatory(true)
+                .withIgnoreCase(true)
                 .withConfigurer(configurer)
                 .withProperties(properties)
                 .bind();
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/ExpressionReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/ExpressionReifier.java
index dd775a1..4e50324 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/ExpressionReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/ExpressionReifier.java
@@ -275,6 +275,7 @@ public class ExpressionReifier<T extends ExpressionDefinition> extends AbstractR
         }
         PropertyBindingSupport.build()
                 .withConfigurer(configurer)
+                .withIgnoreCase(true)
                 .bind(camelContext, target, properties);
     }
 
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
index 6df994b..cf3bdf1 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
@@ -447,8 +447,8 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone
         } else {
             configurer = null;
         }
-        // use advanced binding
-        PropertyBindingSupport.build().withConfigurer(configurer).bind(camelContext, bean, parameters);
+        // use configurer and ignore case as end users may type an option name with mixed case
+        PropertyBindingSupport.build().withConfigurer(configurer).withIgnoreCase(true).bind(camelContext, bean, parameters);
     }
 
     @Override
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
index 92d008f..3e89bba 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
@@ -427,8 +427,8 @@ public abstract class DefaultEndpoint extends ServiceSupport implements Endpoint
         } else if (bean instanceof PropertyConfigurerAware) {
             configurer = ((PropertyConfigurerAware) bean).getPropertyConfigurer(bean);
         }
-        // use advanced binding
-        PropertyBindingSupport.build().withConfigurer(configurer).bind(camelContext, bean, parameters);
+        // use configurer and ignore case as end users may type an option name with mixed case
+        PropertyBindingSupport.build().withConfigurer(configurer).withIgnoreCase(true).bind(camelContext, bean, parameters);
     }
 
     /**
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java
index d9b14a9..2910e83 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java
@@ -76,7 +76,7 @@ public final class RestProducerFactoryHelper {
 
         // component was not added to the context we can configure it
         final Component newlyCreated = camelContext.getComponent(componentName, true, false);
-        PropertyBindingSupport.build().withRemoveParameters(false)
+        PropertyBindingSupport.build().withRemoveParameters(false).withIgnoreCase(true)
                 .withConfigurer(newlyCreated.getComponentPropertyConfigurer())
                 .bind(camelContext, newlyCreated, componentProperties);
         ServiceHelper.startService(newlyCreated);
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 5090e33..38d9f1a 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
@@ -131,6 +131,7 @@ public abstract class AbstractApiComponent<E extends Enum<E> & ApiName, T, S ext
                 .resolvePropertyConfigurer(endpointConfiguration.getClass().getName(), getCamelContext());
         PropertyBindingSupport.build()
                 .withConfigurer(configurer)
+                .withIgnoreCase(true)
                 .bind(getCamelContext(), endpointConfiguration, componentProperties);
         return endpointConfiguration;
     }


[camel] 02/02: CAMEL-15764: api component should not use reflection when configuring their endpoints.

Posted by da...@apache.org.
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

commit 4899ea9d5aaf0b7757411736982e60036e0618b3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Dec 5 15:09:17 2020 +0100

    CAMEL-15764: api component should not use reflection when configuring their endpoints.
---
 .../camel/component/twilio/TwilioEndpointTest.java | 49 ++++++++++++++++++++++
 .../support/component/AbstractApiEndpoint.java     | 34 ++++++++++++++-
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/components/camel-twilio/src/test/java/org/apache/camel/component/twilio/TwilioEndpointTest.java b/components/camel-twilio/src/test/java/org/apache/camel/component/twilio/TwilioEndpointTest.java
new file mode 100644
index 0000000..62f7f3e
--- /dev/null
+++ b/components/camel-twilio/src/test/java/org/apache/camel/component/twilio/TwilioEndpointTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.component.twilio;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.LoggingLevel;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TwilioEndpointTest extends AbstractTwilioTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+        ecc.getBeanIntrospection().setLoggingLevel(LoggingLevel.INFO);
+        return context;
+    }
+
+    @Test
+    public void testTwilioEndpoint() throws Exception {
+        // should not use reflection when creating and configuring endpoint
+
+        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+        long before = ecc.getBeanIntrospection().getInvokedCounter();
+
+        TwilioEndpoint te = context.getEndpoint("twilio:account/fetcher?pathSid=123", TwilioEndpoint.class);
+        AccountEndpointConfiguration aec = (AccountEndpointConfiguration) te.getConfiguration();
+        Assertions.assertEquals("123", aec.getPathSid());
+
+        long after = ecc.getBeanIntrospection().getInvokedCounter();
+        Assertions.assertEquals(before, after);
+    }
+}
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
index 6e2cd7f..c2d1499 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
@@ -31,8 +31,11 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.spi.ExecutorServiceManager;
+import org.apache.camel.spi.PropertyConfigurer;
 import org.apache.camel.spi.ThreadPoolProfile;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.PropertyBindingSupport;
+import org.apache.camel.support.PropertyConfigurerHelper;
 import org.apache.camel.support.ScheduledPollEndpoint;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
@@ -97,8 +100,35 @@ public abstract class AbstractApiEndpoint<E extends ApiName, T>
 
     @Override
     public void configureProperties(Map<String, Object> options) {
-        super.configureProperties(options);
-        setProperties(getConfiguration(), options);
+        if (options != null && !options.isEmpty()) {
+            // configure scheduler first
+            configureScheduledPollConsumerProperties(options);
+
+            PropertyConfigurer configurer = getComponent().getEndpointPropertyConfigurer();
+            PropertyConfigurer configurer2
+                    = PropertyConfigurerHelper.resolvePropertyConfigurer(getCamelContext(), getConfiguration());
+
+            // we have a mix of options that are general endpoint and then specialized
+            // so we need to configure first without reflection
+            // use configurer and ignore case as end users may type an option name with mixed case
+            PropertyBindingSupport.build().withConfigurer(configurer)
+                    .withIgnoreCase(true).withReflection(false)
+                    .bind(getCamelContext(), this, options);
+            PropertyBindingSupport.build().withConfigurer(configurer2)
+                    .withIgnoreCase(true).withReflection(false)
+                    .bind(getCamelContext(), getConfiguration(), options);
+
+            // after reflection-free then we fallback to allow reflection
+            // in case some options are still left
+            if (!options.isEmpty()) {
+                PropertyBindingSupport.build().withConfigurer(configurer)
+                        .withIgnoreCase(true).withReflection(true)
+                        .bind(getCamelContext(), this, options);
+                PropertyBindingSupport.build().withConfigurer(configurer2)
+                        .withIgnoreCase(true).withReflection(true)
+                        .bind(getCamelContext(), getConfiguration(), options);
+            }
+        }
 
         // validate and initialize state
         initState();