camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] camel git commit: CAMEL-7821: BridgePropertyPlaceholderConfigurer fails to use custom PropertiesParser
Date Sun, 15 Feb 2015 15:19:56 GMT
CAMEL-7821: BridgePropertyPlaceholderConfigurer fails to use custom PropertiesParser


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

Branch: refs/heads/camel-2.13.x
Commit: 492dd2dbae113ec92b0048bf01aaaef02074696f
Parents: 95d57d8
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Feb 15 16:20:02 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Feb 15 16:20:27 2015 +0100

----------------------------------------------------------------------
 .../SpringJasyptBridgePropertiesTest.java       | 43 +++++++++++++++++++
 .../jasypt/SpringJasyptBridgePropertiesTest.xml | 43 +++++++++++++++++++
 .../BridgePropertyPlaceholderConfigurer.java    | 44 ++++++++++++++++++--
 3 files changed, 126 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/492dd2db/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
new file mode 100644
index 0000000..2191521
--- /dev/null
+++ b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jasypt;
+
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class SpringJasyptBridgePropertiesTest extends CamelSpringTestSupport {
+
+    @Test
+    public void testJasyptProperties() throws Exception {
+        getMockEndpoint("mock:tiger").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/492dd2db/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
new file mode 100644
index 0000000..11ec9cf
--- /dev/null
+++ b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- define the jasypt properties parser with the given password to be used -->
+  <bean id="jasyptParser" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
+    <property name="password" value="secret"/>
+  </bean>
+
+  <!-- bridge to spring property placeholder -->
+  <bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
+    <property name="location" value="classpath:org/apache/camel/component/jasypt/myproperties.properties"/>
+    <property name="parser" ref="jasyptParser"/>
+  </bean>
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="direct:start"/>
+      <to uri="{{cool.result}}"/>
+    </route>
+  </camelContext>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/492dd2db/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 17b4b1f..68659b1 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
@@ -185,12 +185,14 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
     }
 
     public void setParser(PropertiesParser parser) {
-        this.parser = parser;
+        if (this.parser != null) {
+            // use a bridge if there is already a parser configured
+            this.parser = new BridgePropertiesParser(this.parser, parser);
+        } else {
+            this.parser = parser;
+        }
     }
 
-    /**
-     * {@link PropertyPlaceholderHelper.PlaceholderResolver} to support using
-     */
     private class BridgePropertyPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver
{
 
         private final Properties properties;
@@ -214,5 +216,39 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
         }
     }
 
+    private class BridgePropertiesParser implements PropertiesParser {
+
+        private final PropertiesParser delegate;
+        private final PropertiesParser parser;
+
+        private BridgePropertiesParser(PropertiesParser delegate, PropertiesParser parser)
{
+            this.delegate = delegate;
+            this.parser = parser;
+        }
+
+        @Override
+        public String parseUri(String text, Properties properties, String prefixToken, String
suffixToken) throws IllegalArgumentException {
+            String answer = null;
+            if (delegate != null) {
+                answer = delegate.parseUri(text, properties, prefixToken, suffixToken);
+            }
+            if (answer != null) {
+                text = answer;
+            }
+            return parser.parseUri(text, properties, prefixToken, suffixToken);
+        }
+
+        @Override
+        public String parseProperty(String key, String value, Properties properties) {
+            String answer = null;
+            if (delegate != null) {
+                answer = delegate.parseProperty(key, value, properties);
+            }
+            if (answer != null) {
+                value = answer;
+            }
+            return parser.parseProperty(key, value, properties);
+        }
+    }
 
 }


Mime
View raw message