Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0DE9A9C9C for ; Sat, 25 May 2013 14:51:57 +0000 (UTC) Received: (qmail 4902 invoked by uid 500); 25 May 2013 14:51:55 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 4790 invoked by uid 500); 25 May 2013 14:51:54 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 4720 invoked by uid 99); 25 May 2013 14:51:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 May 2013 14:51:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C8E11318826; Sat, 25 May 2013 14:51:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Sat, 25 May 2013 14:51:52 -0000 Message-Id: In-Reply-To: <321d918de64f468394c8728d64241926@git.apache.org> References: <321d918de64f468394c8728d64241926@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] git commit: CAMEL-6326: Fixed spring bridge property placeholder with nested environment variables. 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 Authored: Sat May 25 16:50:03 2013 +0200 Committer: Claus Ibsen 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; + } + } + + }