Repository: camel
Updated Branches:
  refs/heads/camel-2.19.x 221e0f25f -> bc186de09


CAMEL-11289: camel-ehcache: allow to configure cache manager on component


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bc186de0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bc186de0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bc186de0

Branch: refs/heads/camel-2.19.x
Commit: bc186de0910315abdc50a8c5c80b022911461520
Parents: 221e0f2
Author: lburgazzoli <lburgazz...@gmail.com>
Authored: Tue May 16 18:05:19 2017 +0200
Committer: lburgazzoli <lburgazz...@gmail.com>
Committed: Tue May 16 18:05:19 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/ehcache-component.adoc        | 11 +++++-
 .../component/ehcache/EhcacheComponent.java     | 33 +++++++++++++-----
 .../EhcacheComponentAutoConfiguration.java      | 35 ++++++++++++++++++--
 .../EhcacheComponentConfiguration.java          | 17 ++++++++++
 4 files changed, 85 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bc186de0/components/camel-ehcache/src/main/docs/ehcache-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-ehcache/src/main/docs/ehcache-component.adoc 
b/components/camel-ehcache/src/main/docs/ehcache-component.adoc
index 09f7b82..714d317 100644
--- a/components/camel-ehcache/src/main/docs/ehcache-component.adoc
+++ b/components/camel-ehcache/src/main/docs/ehcache-component.adoc
@@ -37,7 +37,16 @@ format, `?option=value&option=#beanRef&...`
 
 
 // component options: START
-The Ehcache component has no options.
+The Ehcache component supports 2 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|=======================================================================
+| Name | Description | Default | Type
+| **cacheManager** (advanced) | The cache manager |  | CacheManager
+| **resolveProperty Placeholders** (advanced) | Whether the component should 
resolve property placeholders on itself when starting. Only properties which 
are of String type can use property placeholders. | true | boolean
+|=======================================================================
 // component options: END
 
 

http://git-wip-us.apache.org/repos/asf/camel/blob/bc186de0/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
 
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
index bccc39e..9118f30 100644
--- 
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
+++ 
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheComponent.java
@@ -21,11 +21,15 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+import org.ehcache.CacheManager;
 
 /**
  * Represents the component that manages {@link DefaultComponent}.
  */
 public class EhcacheComponent extends DefaultComponent {
+    @Metadata(label = "advanced")
+    private CacheManager cacheManager;
     
     public EhcacheComponent() {
     }
@@ -36,13 +40,26 @@ public class EhcacheComponent extends DefaultComponent {
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
-        return new EhcacheEndpoint(
-            uri,
-            this,
-            EhcacheConfiguration.create(
-                getCamelContext(),
-                remaining,
-                parameters)
-        );
+        EhcacheConfiguration configuration = 
EhcacheConfiguration.create(getCamelContext(), remaining, parameters);
+        if (configuration.getCacheManager() == null) {
+            configuration.setCacheManager(cacheManager);
+        }
+
+        return new EhcacheEndpoint(uri, this, configuration);
+    }
+
+    // *****************************
+    // Properties
+    // *****************************
+
+    public CacheManager getCacheManager() {
+        return cacheManager;
+    }
+
+    /**
+     * The cache manager
+     */
+    public void setCacheManager(CacheManager cacheManager) {
+        this.cacheManager = cacheManager;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/bc186de0/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
index ece5cf2..4d42fdc 100644
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.ehcache.springboot;
 
+import java.util.HashMap;
+import java.util.Map;
 import javax.annotation.Generated;
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.ehcache.EhcacheComponent;
+import org.apache.camel.util.IntrospectionSupport;
 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
 import org.springframework.boot.autoconfigure.condition.ConditionMessage;
 import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
@@ -27,6 +30,7 @@ import 
org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import 
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
 import org.springframework.boot.bind.RelaxedPropertyResolver;
+import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ConditionContext;
 import org.springframework.context.annotation.Conditional;
@@ -42,16 +46,43 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
 @ConditionalOnBean(type = 
"org.apache.camel.spring.boot.CamelAutoConfiguration")
 @Conditional(EhcacheComponentAutoConfiguration.Condition.class)
 @AutoConfigureAfter(name = 
"org.apache.camel.spring.boot.CamelAutoConfiguration")
+@EnableConfigurationProperties(EhcacheComponentConfiguration.class)
 public class EhcacheComponentAutoConfiguration {
 
     @Lazy
     @Bean(name = "ehcache-component")
     @ConditionalOnClass(CamelContext.class)
     @ConditionalOnMissingBean(EhcacheComponent.class)
-    public EhcacheComponent configureEhcacheComponent(CamelContext 
camelContext)
-            throws Exception {
+    public EhcacheComponent configureEhcacheComponent(
+            CamelContext camelContext,
+            EhcacheComponentConfiguration configuration) throws Exception {
         EhcacheComponent component = new EhcacheComponent();
         component.setCamelContext(camelContext);
+        Map<String, Object> parameters = new HashMap<>();
+        IntrospectionSupport.getProperties(configuration, parameters, null,
+                false);
+        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+            Object value = entry.getValue();
+            Class<?> paramClass = value.getClass();
+            if (paramClass.getName().endsWith("NestedConfiguration")) {
+                Class nestedClass = null;
+                try {
+                    nestedClass = (Class) paramClass.getDeclaredField(
+                            "CAMEL_NESTED_CLASS").get(null);
+                    HashMap<String, Object> nestedParameters = new HashMap<>();
+                    IntrospectionSupport.getProperties(value, nestedParameters,
+                            null, false);
+                    Object nestedProperty = nestedClass.newInstance();
+                    IntrospectionSupport.setProperties(camelContext,
+                            camelContext.getTypeConverter(), nestedProperty,
+                            nestedParameters);
+                    entry.setValue(nestedProperty);
+                } catch (NoSuchFieldException e) {
+                }
+            }
+        }
+        IntrospectionSupport.setProperties(camelContext,
+                camelContext.getTypeConverter(), component, parameters);
         return component;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/bc186de0/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
index 4593d88..2b37c3f 100644
--- 
a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
+++ 
b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
@@ -16,7 +16,10 @@
  */
 package org.apache.camel.component.ehcache.springboot;
 
+import javax.annotation.Generated;
+import org.ehcache.CacheManager;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
 
 /**
  * The ehcache component enables you to perform caching operations using 
Ehcache
@@ -24,16 +27,30 @@ import 
org.springframework.boot.context.properties.ConfigurationProperties;
  * 
  * Generated by camel-package-maven-plugin - do not edit this file!
  */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
 @ConfigurationProperties(prefix = "camel.component.ehcache")
 public class EhcacheComponentConfiguration {
 
     /**
+     * The cache manager
+     */
+    @NestedConfigurationProperty
+    private CacheManager cacheManager;
+    /**
      * Whether the component should resolve property placeholders on itself 
when
      * starting. Only properties which are of String type can use property
      * placeholders.
      */
     private Boolean resolvePropertyPlaceholders = true;
 
+    public CacheManager getCacheManager() {
+        return cacheManager;
+    }
+
+    public void setCacheManager(CacheManager cacheManager) {
+        this.cacheManager = cacheManager;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }

Reply via email to