camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1463994 - in /camel/branches/camel-2.10.x: ./ components/camel-spring/src/main/java/org/apache/camel/spring/ components/camel-spring/src/main/java/org/apache/camel/spring/spi/ components/camel-spring/src/test/java/org/apache/camel/componen...
Date Wed, 03 Apr 2013 13:16:48 GMT
Author: davsclaus
Date: Wed Apr  3 13:16:48 2013
New Revision: 1463994

URL: http://svn.apache.org/r1463994
Log:
CAMEL-6233: BridgePropertyPlaceholderConfigurer does not support nested Spring properties

Added:
    camel/branches/camel-2.10.x/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.java
      - copied unchanged from r1463987, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.java
    camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml
      - copied unchanged from r1463987, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml
    camel/branches/camel-2.10.x/components/camel-spring/src/test/resources/org/apache/camel/component/properties/nested.properties
      - copied unchanged from r1463987, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/nested.properties
Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1463987

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=1463994&r1=1463993&r2=1463994&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Wed Apr  3 13:16:48 2013
@@ -250,8 +250,11 @@ public class CamelContextFactoryBean ext
             PropertiesComponent pc = getContext().getComponent("properties", PropertiesComponent.class);
             // replace existing resolver with us
             configurer.setResolver(pc.getPropertiesResolver());
+            configurer.setParser(pc.getPropertiesParser());
             String ref = "ref:" + id;
+            // use the bridge to handle the resolve and parsing
             pc.setPropertiesResolver(configurer);
+            pc.setPropertiesParser(configurer);
             // and update locations to have our as ref first
             String[] locations = pc.getLocations();
             String[] updatedLocations;

Modified: camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java?rev=1463994&r1=1463993&r2=1463994&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
Wed Apr  3 13:16:48 2013
@@ -19,29 +19,36 @@ package org.apache.camel.spring.spi;
 import java.util.Properties;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.component.properties.AugmentedPropertyNameAwarePropertiesParser;
+import org.apache.camel.component.properties.PropertiesParser;
 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.util.PropertyPlaceholderHelper;
 
 /**
  * A {@link PropertyPlaceholderConfigurer} that bridges Camel's <a href="http://camel.apache.org/using-propertyplaceholder.html">
  * property placeholder</a> with the Spring property placeholder mechanism.
  */
-public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements
PropertiesResolver {
+public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements
PropertiesResolver, AugmentedPropertyNameAwarePropertiesParser {
 
     // NOTE: this class must be in the spi package as if its in the root package, then Spring
fails to parse the XML
     // files due some weird spring issue. But that is okay as having this class in the spi
package is fine anyway.
 
     private final Properties properties = new Properties();
     private PropertiesResolver resolver;
+    private PropertiesParser parser;
     private String id;
+    private PropertyPlaceholderHelper helper;
 
     @Override
     protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
Properties props) throws BeansException {
+        super.processProperties(beanFactoryToProcess, props);
         // store all the spring properties so we can refer to them later
         properties.putAll(props);
-        super.processProperties(beanFactoryToProcess, props);
+        // create helper
+        helper = new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix, valueSeparator,
ignoreUnresolvablePlaceholders);
     }
 
     @Override
@@ -69,7 +76,67 @@ public class BridgePropertyPlaceholderCo
         return answer;
     }
 
+    @Override
+    public String parseUri(String text, Properties properties, String prefixToken, String
suffixToken,
+                           String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty)
throws IllegalArgumentException {
+
+        // first let Camel parse the text as it may contain Camel placeholders
+        String answer;
+        if (parser instanceof AugmentedPropertyNameAwarePropertiesParser) {
+            answer = ((AugmentedPropertyNameAwarePropertiesParser) parser).parseUri(text,
properties, prefixToken, suffixToken,
+                    propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty);
+        } else {
+            answer = parser.parseUri(text, properties, prefixToken, suffixToken);
+        }
+
+        // then let Spring parse it to resolve any Spring placeholders
+        if (answer != null) {
+            answer = springResolvePlaceholders(answer, properties);
+        } else {
+            answer = springResolvePlaceholders(text, properties);
+        }
+        return answer;
+    }
+
+    @Override
+    public String parseUri(String text, Properties properties, String prefixToken, String
suffixToken) throws IllegalArgumentException {
+        String answer = parser.parseUri(text, properties, prefixToken, suffixToken);
+        if (answer != null) {
+            answer = springResolvePlaceholders(answer, properties);
+        } else {
+            answer = springResolvePlaceholders(text, properties);
+        }
+        return answer;
+    }
+
+    @Override
+    public String parseProperty(String key, String value, Properties properties) {
+        String answer = parser.parseProperty(key, value, properties);
+        if (answer != null) {
+            answer = springResolvePlaceholders(answer, properties);
+        } else {
+            answer = springResolvePlaceholders(value, properties);
+        }
+        return answer;
+    }
+
+    /**
+     * Resolves the placeholders using Spring's property placeholder functionality.
+     *
+     * @param text   the text which may contain spring placeholders
+     * @param properties the properties
+     * @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);
+    }
+
     public void setResolver(PropertiesResolver resolver) {
         this.resolver = resolver;
     }
+
+    public void setParser(PropertiesParser parser) {
+        this.parser = parser;
+    }
+
 }



Mime
View raw message