Updated Branches: refs/heads/camel-2.10.x 4c8349029 -> 8d97a4711 refs/heads/camel-2.11.x 64b1bc0f1 -> 9ac40a69d refs/heads/master f6551292b -> 456deafba
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/456deafb Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/456deafb Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/456deafb Branch: refs/heads/master Commit: 456deafba90f5c31caaed5dfc75ac2164437ffa2 Parents: f655129 Author: Claus Ibsen <davscl...@apache.org> Authored: Sat May 25 16:50:03 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat May 25 16:50:03 2013 +0200 ---------------------------------------------------------------------- .../spi/BridgePropertyPlaceholderConfigurer.java | 44 ++++++++++++++- 1 files changed, 43 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/456deafb/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; + } + } + + }