Repository: camel Updated Branches: refs/heads/camel-2.13.x 95d57d854 -> 492dd2dba refs/heads/camel-2.14.x da5950194 -> 725e53c32 refs/heads/master a9982a2d9 -> 35752c2e6
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/35752c2e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/35752c2e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/35752c2e Branch: refs/heads/master Commit: 35752c2e64a939109f16e7e24ae85ed1389dc62b Parents: a9982a2 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Feb 15 16:20:02 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Feb 15 16:20:02 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/35752c2e/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/35752c2e/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/35752c2e/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); + } + } }