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 2019/11/12 09:58:03 UTC

[camel] branch master updated: CAMEL-14169: Make it easier to configure global endpoint options once

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 fbe835b  CAMEL-14169: Make it easier to configure global endpoint options once
fbe835b is described below

commit fbe835be787ce48427cf4bdb1150017b86444c39
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 12 10:57:44 2019 +0100

    CAMEL-14169: Make it easier to configure global endpoint options once
---
 .../org/apache/camel/support/DefaultComponent.java | 51 ++++++++++++----------
 1 file changed, 29 insertions(+), 22 deletions(-)

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 2e707ff..b225e73 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
@@ -138,17 +138,32 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone
             // but at debug level only output sanitized uris
             log.debug("Creating endpoint uri=[{}], path=[{}]", URISupport.sanitizeUri(uri), URISupport.sanitizePath(path));
         }
+
+        // extract these global options and infer their value based on global/component level configuration
+        boolean basic = getAndRemoveParameter(parameters, "basicPropertyBinding", boolean.class, basicPropertyBinding ?
+                basicPropertyBinding : getCamelContext().getGlobalEndpointConfiguration().isBasicPropertyBinding());
+        boolean bridge = getAndRemoveParameter(parameters, "bridgeErrorHandler", boolean.class, bridgeErrorHandler ?
+                bridgeErrorHandler : getCamelContext().getGlobalEndpointConfiguration().isBridgeErrorHandler());
+        boolean lazy = getAndRemoveParameter(parameters, "lazyStartProducer", boolean.class, lazyStartProducer ?
+                lazyStartProducer : getCamelContext().getGlobalEndpointConfiguration().isLazyStartProducer());
+
+        // create endpoint
         Endpoint endpoint = createEndpoint(uri, path, parameters);
         if (endpoint == null) {
             return null;
         }
+        // inject camel context
+        endpoint.setCamelContext(getCamelContext());
 
-        // setup whether to use basic property binding or not which must be done before we set properties
-        boolean basic = getAndRemoveParameter(parameters, "basicPropertyBinding", boolean.class, basicPropertyBinding);
+        // and setup those global options afterwards
         if (endpoint instanceof DefaultEndpoint) {
-            ((DefaultEndpoint) endpoint).setBasicPropertyBinding(basic);
+            DefaultEndpoint de = (DefaultEndpoint) endpoint;
+            de.setBasicPropertyBinding(basic);
+            de.setBridgeErrorHandler(bridge);
+            de.setLazyStartProducer(lazy);
         }
 
+        // configure remainder of the parameters
         endpoint.configureProperties(parameters);
         if (useIntrospectionOnEndpoint()) {
             setProperties(endpoint, parameters);
@@ -213,39 +228,31 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone
             // but at debug level only output sanitized uris
             log.debug("Creating endpoint uri=[{}], path=[{}]", URISupport.sanitizeUri(uri), URISupport.sanitizePath(path));
         }
+
+        // extract these global options and infer their value based on global/component level configuration
+        boolean basic = getAndRemoveParameter(parameters, "basicPropertyBinding", boolean.class, basicPropertyBinding ?
+                basicPropertyBinding : getCamelContext().getGlobalEndpointConfiguration().isBasicPropertyBinding());
+        boolean bridge = getAndRemoveParameter(parameters, "bridgeErrorHandler", boolean.class, bridgeErrorHandler ?
+                bridgeErrorHandler : getCamelContext().getGlobalEndpointConfiguration().isBridgeErrorHandler());
+        boolean lazy = getAndRemoveParameter(parameters, "lazyStartProducer", boolean.class, lazyStartProducer ?
+                lazyStartProducer : getCamelContext().getGlobalEndpointConfiguration().isLazyStartProducer());
+
         Endpoint endpoint = createEndpoint(uri, path, parameters);
         if (endpoint == null) {
             return null;
         }
-
         // inject camel context
         endpoint.setCamelContext(getCamelContext());
 
-        // setup global options
-        if (endpoint instanceof DefaultEndpoint) {
-            DefaultEndpoint de = (DefaultEndpoint) endpoint;
-            de.setBasicPropertyBinding(getCamelContext().getGlobalEndpointConfiguration().isBasicPropertyBinding());;
-            de.setBridgeErrorHandler(getCamelContext().getGlobalEndpointConfiguration().isBridgeErrorHandler());;
-            de.setLazyStartProducer(getCamelContext().getGlobalEndpointConfiguration().isLazyStartProducer());;
-        }
-
-        // setup global options which must be done before we set properties
+        // and setup those global options afterwards
         if (endpoint instanceof DefaultEndpoint) {
             DefaultEndpoint de = (DefaultEndpoint) endpoint;
-            boolean defaultBasic = basicPropertyBinding ? basicPropertyBinding : getCamelContext().getGlobalEndpointConfiguration().isBasicPropertyBinding();
-            boolean basic = getAndRemoveParameter(parameters, "basicPropertyBinding", boolean.class, defaultBasic);
             de.setBasicPropertyBinding(basic);
-
-            boolean defaultBridge = bridgeErrorHandler ? bridgeErrorHandler : getCamelContext().getGlobalEndpointConfiguration().isBridgeErrorHandler();
-            boolean bridge = getAndRemoveParameter(parameters, "bridgeErrorHandler", boolean.class, defaultBridge);
             de.setBridgeErrorHandler(bridge);
-
-            boolean defaultLazy = lazyStartProducer ? lazyStartProducer : getCamelContext().getGlobalEndpointConfiguration().isLazyStartProducer();
-            boolean lazy = getAndRemoveParameter(parameters, "lazyStartProducer", boolean.class, defaultLazy);
             de.setLazyStartProducer(lazy);
         }
 
-        // configure parameters
+        // configure remainder of the parameters
         endpoint.configureProperties(parameters);
         if (useIntrospectionOnEndpoint()) {
             setProperties(endpoint, parameters);