You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/02/15 16:19:55 UTC
[2/3] camel git commit: CAMEL-7821:
BridgePropertyPlaceholderConfigurer fails to use custom PropertiesParser
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/725e53c3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/725e53c3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/725e53c3
Branch: refs/heads/camel-2.14.x
Commit: 725e53c3240ead831ddad8ddcb525fad8824b6de
Parents: da59501
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 15 16:20:02 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 15 16:20:17 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/725e53c3/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/725e53c3/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/725e53c3/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 3108acf..eeb260d 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
@@ -197,12 +197,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;
@@ -226,5 +228,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);
+ }
+ }
}