camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1463987 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/ main/java/org/apache/camel/spring/spi/ test/java/org/apache/camel/component/properties/ test/resources/org/apache/camel/component/properties/
Date Wed, 03 Apr 2013 12:58:13 GMT
Author: davsclaus
Date: Wed Apr  3 12:58:13 2013
New Revision: 1463987

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

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.java
      - copied, changed from r1463883, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml
      - copied, changed from r1463883, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurer2Test.xml
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/nested.properties
      - copied, changed from r1463883, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=1463987&r1=1463986&r2=1463987&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Wed Apr  3 12:58:13 2013
@@ -252,8 +252,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/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java?rev=1463987&r1=1463986&r2=1463987&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
Wed Apr  3 12:58:13 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;
+    }
+
 }

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.java
(from r1463883, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.java&r1=1463883&r2=1463987&rev=1463987&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.java
Wed Apr  3 12:58:13 2013
@@ -23,15 +23,15 @@ import org.springframework.context.suppo
 /**
  *
  */
-public class CamelSpringPropertyPlaceholderConfigurerTest extends SpringTestSupport {
+public class CamelSpringPropertyPlaceholderConfigurerNestedTest extends SpringTestSupport
{
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.xml");
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml");
     }
 
     public void testCamelSpringPropertyPlaceholderConfigurerTest() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("Bonjour Camel");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("And in French we say bonjour
Camel");
 
         template.sendBody("direct:bar", "Camel");
 

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml
(from r1463883, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurer2Test.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurer2Test.xml&r1=1463883&r2=1463987&rev=1463987&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurer2Test.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerNestedTest.xml
Wed Apr  3 12:58:13 2013
@@ -24,7 +24,7 @@
   <!-- bridge spring property placeholder with Camel -->
   <!-- you must NOT use the <context:property-placeholder at the same time, only this
bridge bean -->
   <bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
-    <p:property name="location" value="classpath:org/apache/camel/component/properties/cheese.properties"/>
+    <p:property name="location" value="classpath:org/apache/camel/component/properties/nested.properties"/>
   </bean>
 
   <!-- a bean that uses Spring property placeholder -->
@@ -34,14 +34,11 @@
   </bean>
 
   <camelContext xmlns="http://camel.apache.org/schema/spring">
-    <!-- also define Camel properties placeholder where we can configure it as well -->
-    <propertyPlaceholder id="properties" location="classpath:org/apache/camel/component/properties/myprop.properties"/>
     <!-- in this route we use Camels property placeholder {{ }} style -->
     <route>
       <from uri="direct:{{cool.bar}}"/>
       <bean ref="hello"/>
-      <!-- this property is from the Camel property placeholder, and not from spring -->
-      <to uri="{{result}}"/>
+      <to uri="{{cool.end}}"/>
     </route>
   </camelContext>
 

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/nested.properties
(from r1463883, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/nested.properties?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/nested.properties&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties&r1=1463883&r2=1463987&rev=1463987&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/cheese.properties
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/nested.properties
Wed Apr  3 12:58:13 2013
@@ -15,13 +15,8 @@
 ## limitations under the License.
 ## ------------------------------------------------------------------------
 
-cool.end=mock:result
+cool.end=mock:${cool.bar}
 cool.bar=bar
 
-myCoolCharset=iso-8859-1
-slipDelimiter=##
-
-delay=25
-max=3
-
-hi=Bonjour
\ No newline at end of file
+hi=And in French we say ${more}
+more=bonjour
\ No newline at end of file



Mime
View raw message