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/05/07 18:24:46 UTC

[2/2] camel git commit: CAMEL-8746: Jasypt with BridgePropertyPlaceholderConfigurer is not handling spring property injection with defaults anymore. Thanks to Oliver Holzmann for the patch.

CAMEL-8746: Jasypt with BridgePropertyPlaceholderConfigurer is not handling spring property injection with defaults anymore. Thanks to Oliver Holzmann for the patch.


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

Branch: refs/heads/camel-2.15.x
Commit: 1b3867a6b3b9c4b4065194e28a783f8d8aa16244
Parents: 2749481
Author: Claus Ibsen <da...@apache.org>
Authored: Thu May 7 18:28:04 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu May 7 18:28:39 2015 +0200

----------------------------------------------------------------------
 .../jasypt/JasyptPropertiesParser.java          | 14 +++---
 .../jasypt/JasyptPropertiesParserTest.java      |  7 +++
 ...pringJasyptBridgePropertiesAutowireTest.java | 44 ++++++++++++++++
 .../camel/component/jasypt/SpringTest.java      | 40 +++++++++++++++
 ...SpringJasyptBridgePropertiesAutowireTest.xml | 53 ++++++++++++++++++++
 .../component/jasypt/myproperties.properties    |  3 ++
 6 files changed, 155 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1b3867a6/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java b/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java
index c39d086..f089533 100755
--- a/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java
+++ b/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java
@@ -52,12 +52,14 @@ public class JasyptPropertiesParser extends DefaultPropertiesParser {
     @Override
     public String parseProperty(String key, String value, Properties properties) {
         log.trace(format("Parsing property '%s=%s'", key, value));
-        initEncryptor();
-        Matcher matcher = pattern.matcher(value);
-        while (matcher.find()) {
-            log.trace(format("Decrypting part '%s'", matcher.group(0)));
-            String decrypted = encryptor.decrypt(matcher.group(1));
-            value = value.replace(matcher.group(0), decrypted);
+        if (value != null) {
+            initEncryptor();
+            Matcher matcher = pattern.matcher(value);
+            while (matcher.find()) {
+                log.trace(format("Decrypting part '%s'", matcher.group(0)));
+                String decrypted = encryptor.decrypt(matcher.group(1));
+                value = value.replace(matcher.group(0), decrypted);
+            }
         }
         return value;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1b3867a6/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java
index 83c0688..65049a4 100755
--- a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java
+++ b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java
@@ -46,6 +46,13 @@ public class JasyptPropertiesParserTest {
     }
 
     @Test
+    public void testNullPropertyIsUntouched() {
+        String expected = null;
+        String result = jasyptPropertiesParser.parseProperty(KEY, expected, null);
+        assertThat(result, is(expected));
+    }
+
+    @Test
     public void testPlainPropertyIsUntouched() {
         String expected = "http://somehost?1=someval1&2=someval2";
         String result = jasyptPropertiesParser.parseProperty(KEY, expected, null);

http://git-wip-us.apache.org/repos/asf/camel/blob/1b3867a6/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.java b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.java
new file mode 100644
index 0000000..09a0b87
--- /dev/null
+++ b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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 SpringJasyptBridgePropertiesAutowireTest extends CamelSpringTestSupport {
+
+    @Test
+    public void testJasyptProperties() throws Exception {
+        getMockEndpoint("mock:tiger").expectedBodiesReceived("Hello World Data Spring");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext(
+                "org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.xml");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1b3867a6/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringTest.java b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringTest.java
new file mode 100644
index 0000000..160975e
--- /dev/null
+++ b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringTest {
+
+    // defaulted and overwritten in myproperties.properties
+    @Value("${available.prop:no Data}")
+    private String data = "";
+
+    @Value("${missing.prop:Spring}")
+    private String defaulted;
+
+    public void setData(String data) {
+        this.data = data;
+    }
+
+    public String handleRequest(String request) {
+        return request + " " + data + " " + defaulted;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1b3867a6/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.xml b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.xml
new file mode 100644
index 0000000..2f3e3db
--- /dev/null
+++ b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesAutowireTest.xml
@@ -0,0 +1,53 @@
+<?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:context="http://www.springframework.org/schema/context"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="
+       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+       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
+    ">
+
+  <!-- Enables spring config and autowiring through annotations -->
+  <context:component-scan base-package="org.apache.camel.component.jasypt" />
+
+  <!-- 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="bean:springTest" />
+      <to uri="{{cool.result}}" />
+    </route>
+  </camelContext>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/1b3867a6/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/myproperties.properties
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/myproperties.properties b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/myproperties.properties
index 44a2c10..6ca93ba 100644
--- a/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/myproperties.properties
+++ b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/myproperties.properties
@@ -22,3 +22,6 @@ cool.result=mock:{{cool.password}}
 # here is a password which is encrypted
 cool.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
 # END SNIPPET: e1
+
+# overwriting spring properties default
+available.prop = Data