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 2015/08/12 14:29:24 UTC

camel git commit: CAMEL-6062: Camel properties now support property placeholder

Repository: camel
Updated Branches:
  refs/heads/master 2e42b1c20 -> aabb88c42


CAMEL-6062: Camel properties now support property placeholder


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

Branch: refs/heads/master
Commit: aabb88c42732c5f8892f56e81a89ed3307ed5a5c
Parents: 2e42b1c
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 12 14:37:13 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 12 14:37:13 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java    | 18 +++++++++++++++++-
 .../apache/camel/model/PropertiesDefinition.java  |  3 ---
 .../properties/PropertiesComponentTest.java       |  9 +++++++++
 3 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/aabb88c4/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 10fbff9..3cfa60e 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -39,7 +39,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
-
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.naming.Context;
@@ -2664,6 +2663,23 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
 
     private void doStartCamel() throws Exception {
 
+        // custom properties may use property placeholders so resolve those early on
+        if (properties != null && !properties.isEmpty()) {
+            for (Map.Entry<String, String> entry : properties.entrySet()) {
+                String key = entry.getKey();
+                String value = entry.getValue();
+                if (value != null) {
+                    String replaced = resolvePropertyPlaceholders(value);
+                    if (!value.equals(replaced)) {
+                        if (log.isDebugEnabled()) {
+                            log.debug("Camel property with key {} replaced value from {} -> {}", new Object[]{key, value, replaced});
+                        }
+                        entry.setValue(replaced);
+                    }
+                }
+            }
+        }
+
         if (classResolver instanceof CamelContextAware) {
             ((CamelContextAware) classResolver).setCamelContext(this);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/aabb88c4/camel-core/src/main/java/org/apache/camel/model/PropertiesDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/PropertiesDefinition.java b/camel-core/src/main/java/org/apache/camel/model/PropertiesDefinition.java
index 1ad1095..419e4b9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/PropertiesDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/PropertiesDefinition.java
@@ -50,9 +50,6 @@ public class PropertiesDefinition {
         return properties;
     }
     
-    /***
-     * @return A Map of the contained DataFormatType's indexed by id.
-     */
     public Map<String, String> asMap() {
         Map<String, String> propertiesAsMap = new HashMap<String, String>();
         for (PropertyDefinition propertyType : getProperties()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/aabb88c4/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
index 94bf5bb..96d5723 100644
--- a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
@@ -572,10 +572,19 @@ public class PropertiesComponentTest extends ContextTestSupport {
         System.clearProperty("beer");
     }
 
+    public void testCamelProperties() throws Exception {
+        context.start();
+
+        assertEquals("Hello Camel", context.getProperties().get("foo"));
+        assertEquals("cool.name", context.getProperties().get("bar"));
+    }
+
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
         context.addComponent("properties", new PropertiesComponent("classpath:org/apache/camel/component/properties/myproperties.properties"));
+        context.getProperties().put("foo", "Hello {{cool.name}}");
+        context.getProperties().put("bar", "cool.name");
         return context;
     }