camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] git commit: CAMEL-6326: Fixed spring bridge property placeholder with nested environment variables.
Date Sat, 25 May 2013 14:51:52 GMT
CAMEL-6326: Fixed spring bridge property placeholder with nested environment variables.


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

Branch: refs/heads/camel-2.11.x
Commit: 9ac40a69d3f544dc73c24554d3ece3e50269d226
Parents: 64b1bc0
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat May 25 16:50:03 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat May 25 16:50:33 2013 +0200

----------------------------------------------------------------------
 .../spi/BridgePropertyPlaceholderConfigurer.java   |   44 ++++++++++++++-
 1 files changed, 43 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9ac40a69/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
index 74d27ce..17b4b1f 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
@@ -25,6 +25,7 @@ import org.apache.camel.component.properties.PropertiesResolver;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.core.Constants;
 import org.springframework.util.PropertyPlaceholderHelper;
 
 /**
@@ -47,6 +48,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
     private String configuredPlaceholderSuffix;
     private String configuredValueSeparator;
     private Boolean configuredIgnoreUnresolvablePlaceholders;
+    private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;
 
     @Override
     protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
Properties props) throws BeansException {
@@ -68,6 +70,19 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
     }
 
     @Override
+    public void setSystemPropertiesModeName(String constantName) throws IllegalArgumentException
{
+        super.setSystemPropertiesModeName(constantName);
+        Constants constants = new Constants(PropertyPlaceholderConfigurer.class);
+        this.systemPropertiesMode = constants.asNumber(constantName).intValue();
+    }
+
+    @Override
+    public void setSystemPropertiesMode(int systemPropertiesMode) {
+        super.setSystemPropertiesMode(systemPropertiesMode);
+        this.systemPropertiesMode = systemPropertiesMode;
+    }
+
+    @Override
     public void setPlaceholderPrefix(String placeholderPrefix) {
         super.setPlaceholderPrefix(placeholderPrefix);
         this.configuredPlaceholderPrefix = placeholderPrefix;
@@ -162,7 +177,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
      * @return the parsed text with replaced placeholders, or the original text as is
      */
     protected String springResolvePlaceholders(String text, Properties properties) {
-        return helper.replacePlaceholders(text, properties);
+        return helper.replacePlaceholders(text, new BridgePropertyPlaceholderResolver(properties));
     }
 
     public void setResolver(PropertiesResolver resolver) {
@@ -173,4 +188,31 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
         this.parser = parser;
     }
 
+    /**
+     * {@link PropertyPlaceholderHelper.PlaceholderResolver} to support using
+     */
+    private class BridgePropertyPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver
{
+
+        private final Properties properties;
+
+        public BridgePropertyPlaceholderResolver(Properties properties) {
+            this.properties = properties;
+        }
+
+        public String resolvePlaceholder(String placeholderName) {
+            String propVal = null;
+            if (systemPropertiesMode  == SYSTEM_PROPERTIES_MODE_OVERRIDE) {
+                propVal = resolveSystemProperty(placeholderName);
+            }
+            if (propVal == null) {
+                propVal = (String) properties.get(placeholderName);
+            }
+            if (propVal == null && systemPropertiesMode == SYSTEM_PROPERTIES_MODE_FALLBACK)
{
+                propVal = resolveSystemProperty(placeholderName);
+            }
+            return propVal;
+        }
+    }
+
+
 }


Mime
View raw message