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/12/09 12:42:30 UTC

[camel] branch master updated: CAMEL-14275: Camel component option with Properties should be configurable in SB

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 309cb51  CAMEL-14275: Camel component option with Properties should be configurable in SB
309cb51 is described below

commit 309cb51ce62cf4c07a45372269c89066581e53aa
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 9 13:40:49 2019 +0100

    CAMEL-14275: Camel component option with Properties should be configurable in SB
---
 .../src/main/docs/jcache-component.adoc            |  5 +--
 .../camel/component/jcache/JCacheComponent.java    | 38 ++++++++++++++++++----
 .../endpoint/dsl/JCacheEndpointBuilderFactory.java | 23 ++++++-------
 .../springboot/JCacheComponentConfiguration.java   | 25 ++++++++++----
 4 files changed, 64 insertions(+), 27 deletions(-)

diff --git a/components/camel-jcache/src/main/docs/jcache-component.adoc b/components/camel-jcache/src/main/docs/jcache-component.adoc
index 946876a..af0a5a8 100644
--- a/components/camel-jcache/src/main/docs/jcache-component.adoc
+++ b/components/camel-jcache/src/main/docs/jcache-component.adoc
@@ -112,7 +112,7 @@ The component supports 8 options, which are listed below.
 
 
 // component options: START
-The JCache component supports 7 options, which are listed below.
+The JCache component supports 8 options, which are listed below.
 
 
 
@@ -121,7 +121,8 @@ The JCache component supports 7 options, which are listed below.
 | Name | Description | Default | Type
 | *cachingProvider* (common) | The fully qualified class name of the javax.cache.spi.CachingProvider |  | String
 | *cacheConfiguration* (common) | A Configuration for the Cache |  | Configuration
-| *cacheConfiguration Properties* (common) | The Properties for the javax.cache.spi.CachingProvider to create the CacheManager |  | Properties
+| *cacheConfiguration Properties* (common) | Properties to configure jcache |  | Map
+| *cacheConfiguration PropertiesRef* (common) | References to an existing Properties or Map to lookup in the registry to use for configuring jcache. |  | String
 | *configurationUri* (common) | An implementation specific URI for the CacheManager |  | String
 | *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
diff --git a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheComponent.java b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheComponent.java
index 124ef5b..61cd4b7 100644
--- a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheComponent.java
+++ b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheComponent.java
@@ -26,6 +26,7 @@ import javax.cache.configuration.Configuration;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.DefaultComponent;
 
 /**
@@ -36,7 +37,8 @@ public class JCacheComponent extends DefaultComponent {
 
     private String cachingProvider;
     private Configuration cacheConfiguration;
-    private Properties cacheConfigurationProperties;
+    private String cacheConfigurationPropertiesRef;
+    private Map cacheConfigurationProperties;
     private String configurationUri;
 
     public JCacheComponent() {
@@ -53,13 +55,27 @@ public class JCacheComponent extends DefaultComponent {
 
         configuration.setCachingProvider(cachingProvider);
         configuration.setCacheConfiguration(cacheConfiguration);
-        configuration.setCacheConfigurationProperties(cacheConfigurationProperties);
+        configuration.setCacheConfigurationProperties(loadProperties());
         configuration.setConfigurationUri(configurationUri);
 
         setProperties(configuration, parameters);
         return new JCacheEndpoint(uri, this, configuration);
     }
 
+    private Properties loadProperties() {
+        Properties answer = null;
+        if (cacheConfigurationProperties != null) {
+            answer = new Properties();
+            answer.putAll(cacheConfigurationProperties);
+        }
+        if (answer == null && cacheConfigurationPropertiesRef != null) {
+            Map map = CamelContextHelper.mandatoryLookup(getCamelContext(), cacheConfigurationPropertiesRef, Map.class);
+            answer = new Properties();
+            answer.putAll(map);
+        }
+        return answer;
+    }
+
     /**
      * The fully qualified class name of the {@link javax.cache.spi.CachingProvider}
      */
@@ -83,17 +99,27 @@ public class JCacheComponent extends DefaultComponent {
     }
 
     /**
-     * The {@link Properties} for the {@link javax.cache.spi.CachingProvider} to
-     * create the {@link CacheManager}
+     * Properties to configure jcache
      */
-    public Properties getCacheConfigurationProperties() {
+    public Map getCacheConfigurationProperties() {
         return cacheConfigurationProperties;
     }
 
-    public void setCacheConfigurationProperties(Properties cacheConfigurationProperties) {
+    public void setCacheConfigurationProperties(Map cacheConfigurationProperties) {
         this.cacheConfigurationProperties = cacheConfigurationProperties;
     }
 
+    public String getCacheConfigurationPropertiesRef() {
+        return cacheConfigurationPropertiesRef;
+    }
+
+    /**
+     * References to an existing {@link Properties} or {@link Map} to lookup in the registry to use for configuring jcache.
+     */
+    public void setCacheConfigurationPropertiesRef(String cacheConfigurationPropertiesRef) {
+        this.cacheConfigurationPropertiesRef = cacheConfigurationPropertiesRef;
+    }
+
     /**
      * An implementation specific URI for the {@link CacheManager}
      */
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/JCacheEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/JCacheEndpointBuilderFactory.java
index 757152d..cd691be 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/JCacheEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/JCacheEndpointBuilderFactory.java
@@ -17,7 +17,7 @@
 package org.apache.camel.builder.endpoint.dsl;
 
 import java.util.List;
-import java.util.Properties;
+import java.util.Map;
 import javax.annotation.Generated;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.builder.EndpointConsumerBuilder;
@@ -74,12 +74,12 @@ public interface JCacheEndpointBuilderFactory {
          * The Properties for the javax.cache.spi.CachingProvider to create the
          * CacheManager.
          * 
-         * The option is a: <code>java.util.Properties</code> type.
+         * The option is a: <code>java.util.Map</code> type.
          * 
          * Group: common
          */
         default JCacheEndpointConsumerBuilder cacheConfigurationProperties(
-                Properties cacheConfigurationProperties) {
+                Map cacheConfigurationProperties) {
             doSetProperty("cacheConfigurationProperties", cacheConfigurationProperties);
             return this;
         }
@@ -87,8 +87,7 @@ public interface JCacheEndpointBuilderFactory {
          * The Properties for the javax.cache.spi.CachingProvider to create the
          * CacheManager.
          * 
-         * The option will be converted to a <code>java.util.Properties</code>
-         * type.
+         * The option will be converted to a <code>java.util.Map</code> type.
          * 
          * Group: common
          */
@@ -639,12 +638,12 @@ public interface JCacheEndpointBuilderFactory {
          * The Properties for the javax.cache.spi.CachingProvider to create the
          * CacheManager.
          * 
-         * The option is a: <code>java.util.Properties</code> type.
+         * The option is a: <code>java.util.Map</code> type.
          * 
          * Group: common
          */
         default JCacheEndpointProducerBuilder cacheConfigurationProperties(
-                Properties cacheConfigurationProperties) {
+                Map cacheConfigurationProperties) {
             doSetProperty("cacheConfigurationProperties", cacheConfigurationProperties);
             return this;
         }
@@ -652,8 +651,7 @@ public interface JCacheEndpointBuilderFactory {
          * The Properties for the javax.cache.spi.CachingProvider to create the
          * CacheManager.
          * 
-         * The option will be converted to a <code>java.util.Properties</code>
-         * type.
+         * The option will be converted to a <code>java.util.Map</code> type.
          * 
          * Group: common
          */
@@ -1062,12 +1060,12 @@ public interface JCacheEndpointBuilderFactory {
          * The Properties for the javax.cache.spi.CachingProvider to create the
          * CacheManager.
          * 
-         * The option is a: <code>java.util.Properties</code> type.
+         * The option is a: <code>java.util.Map</code> type.
          * 
          * Group: common
          */
         default JCacheEndpointBuilder cacheConfigurationProperties(
-                Properties cacheConfigurationProperties) {
+                Map cacheConfigurationProperties) {
             doSetProperty("cacheConfigurationProperties", cacheConfigurationProperties);
             return this;
         }
@@ -1075,8 +1073,7 @@ public interface JCacheEndpointBuilderFactory {
          * The Properties for the javax.cache.spi.CachingProvider to create the
          * CacheManager.
          * 
-         * The option will be converted to a <code>java.util.Properties</code>
-         * type.
+         * The option will be converted to a <code>java.util.Map</code> type.
          * 
          * Group: common
          */
diff --git a/platforms/spring-boot/components-starter/camel-jcache-starter/src/main/java/org/apache/camel/component/jcache/springboot/JCacheComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-jcache-starter/src/main/java/org/apache/camel/component/jcache/springboot/JCacheComponentConfiguration.java
index 51d281c..a8d3c53 100644
--- a/platforms/spring-boot/components-starter/camel-jcache-starter/src/main/java/org/apache/camel/component/jcache/springboot/JCacheComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-jcache-starter/src/main/java/org/apache/camel/component/jcache/springboot/JCacheComponentConfiguration.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.jcache.springboot;
 
+import java.util.Map;
 import javax.annotation.Generated;
 import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
 import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -47,10 +48,14 @@ public class JCacheComponentConfiguration
      */
     private String cacheConfiguration;
     /**
-     * The Properties for the javax.cache.spi.CachingProvider to create the
-     * CacheManager. The option is a java.util.Properties type.
+     * Properties to configure jcache
      */
-    private String cacheConfigurationProperties;
+    private Map cacheConfigurationProperties;
+    /**
+     * References to an existing Properties or Map to lookup in the registry to
+     * use for configuring jcache.
+     */
+    private String cacheConfigurationPropertiesRef;
     /**
      * An implementation specific URI for the CacheManager
      */
@@ -97,15 +102,23 @@ public class JCacheComponentConfiguration
         this.cacheConfiguration = cacheConfiguration;
     }
 
-    public String getCacheConfigurationProperties() {
+    public Map getCacheConfigurationProperties() {
         return cacheConfigurationProperties;
     }
 
-    public void setCacheConfigurationProperties(
-            String cacheConfigurationProperties) {
+    public void setCacheConfigurationProperties(Map cacheConfigurationProperties) {
         this.cacheConfigurationProperties = cacheConfigurationProperties;
     }
 
+    public String getCacheConfigurationPropertiesRef() {
+        return cacheConfigurationPropertiesRef;
+    }
+
+    public void setCacheConfigurationPropertiesRef(
+            String cacheConfigurationPropertiesRef) {
+        this.cacheConfigurationPropertiesRef = cacheConfigurationPropertiesRef;
+    }
+
     public String getConfigurationUri() {
         return configurationUri;
     }