Permalink
Browse files

CAMEL-5973: Fixed property placeholder with blueprint and delegate no…

…t working such as when using jasypt.

git-svn-id: https://svn.apache.org/repos/asf/camel/trunk@1433521 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 8627c04 commit ea824995920d07d00915daa0babdef0c3123c60e @davsclaus davsclaus committed Jan 15, 2013
@@ -26,6 +26,7 @@
import org.apache.camel.osgi.CamelContextFactory;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption;
+import org.openengsb.labs.paxexam.karaf.options.LogLevelOption;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
@@ -36,6 +37,7 @@
import org.slf4j.LoggerFactory;
import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.logLevel;
import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
@@ -139,6 +141,9 @@ public static Option loadCamelFeatures(String... features) {
// override the config.properties (to fix pax-exam bug)
replaceConfigurationFile("etc/config.properties", new File("src/test/resources/org/apache/camel/itest/karaf/config.properties")),
replaceConfigurationFile("etc/custom.properties", new File("src/test/resources/org/apache/camel/itest/karaf/custom.properties")),
+
+ // we need INFO logging otherwise we cannot see what happens
+ logLevel(LogLevelOption.LogLevel.INFO),
// install the cxf jaxb spec as the karaf doesn't provide it by default
scanFeatures(getCamelKarafFeatureUrl(), "cxf-jaxb", "camel-core", "camel-spring", "camel-test")};
@@ -0,0 +1,84 @@
+/**
+ * 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.itest.osgi.blueprint;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Constants;
+
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+
+/**
+ *
+ */
+@RunWith(JUnit4TestRunner.class)
+public class BlueprintPropertiesJasyptRouteTest extends OSGiBlueprintTestSupport {
+
+ private String name = BlueprintPropertiesJasyptRouteTest.class.getName();
+
+ @Test
+ public void testBlueprintJasyptProperties() throws Exception {
+ // start bundle
+ getInstalledBundle(name).start();
+
+ // must use the camel context from osgi
+ CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.symbolicname=" + name + ")", 10000);
+
+ ProducerTemplate myTemplate = ctx.createProducerTemplate();
+ myTemplate.start();
+
+ // do our testing
+ MockEndpoint foo = ctx.getEndpoint("mock:foo", MockEndpoint.class);
+ foo.expectedMessageCount(1);
+ MockEndpoint tiger = ctx.getEndpoint("mock:tiger", MockEndpoint.class);
+ tiger.expectedMessageCount(1);
+
+ myTemplate.sendBody("direct:start", "Hello World");
+
+ foo.assertIsSatisfied();
+ tiger.assertIsSatisfied();
+
+ myTemplate.stop();
+ }
+
+ @Configuration
+ public static Option[] configure() throws Exception {
+
+ Option[] options = combine(
+ getDefaultCamelKarafOptions(),
+
+ bundle(newBundle()
+ .add("OSGI-INF/blueprint/test.xml", BlueprintPropertiesJasyptRouteTest.class.getResource("blueprint-26.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME, BlueprintPropertiesJasyptRouteTest.class.getName())
+ .set(Constants.BUNDLE_VERSION, "1.0.0")
+ .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
+ .build()).noStart(),
+
+ // using the features to install the camel components
+ loadCamelFeatures("camel-blueprint", "camel-jasypt"));
+
+ return options;
+ }
+
+}
@@ -0,0 +1,52 @@
+<?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.
+-->
+<!-- START SNIPPET: e1 -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- OSGI blueprint property placeholder -->
+ <cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint">
+ <cm:default-properties>
+ <cm:property name="cool.password" value="ENC(bsW9uV37gQ0QHFu7KO03Ww==)"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
+ <property name="password" value="secret"/>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <!-- use placeholder, and refer to the jasyp parser so we support the encrypted values -->
+ <propertyPlaceholder id="properties" location="blueprint:myblueprint.placeholder" propertiesParserRef="jasypt"/>
+
+ <!-- in the route we can use {{ }} placeholders which will lookup in blueprint
+ as Camel will auto detect the OSGi blueprint property placeholder and use it -->
+ <route>
+ <from uri="direct:start"/>
+ <to uri="mock:foo"/>
+ <to uri="mock:{{cool.password}}"/>
+ </route>
+
+ </camelContext>
+
+</blueprint>
+<!-- END SNIPPET: e1 -->
@@ -0,0 +1,23 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+# refer to a mock endpoint name by that encrypted password
+cool.result=mock:{{cool.password}}
+
+# here is a password which is encrypted
+cool.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
+

0 comments on commit ea82499

Please sign in to comment.