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 2011/02/26 10:24:54 UTC
svn commit: r1074807 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/component/properties/
components/camel-blueprint/src/main/java/org/apache/camel/blueprint/
components/camel-core-xml/src/main/java/org/apache/camel/core/xml/
components/c...
Author: davsclaus
Date: Sat Feb 26 09:24:53 2011
New Revision: 1074807
URL: http://svn.apache.org/viewvc?rev=1074807&view=rev
Log:
CAMEL-3674: Added support for blueprint location to Camel properties component to bridge Blueprint and Camel. This allows you to use Blueprint placeholder in Camel routes.
Added:
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesResolver.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintExplicitPropertiesRouteTest.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintPropertiesRouteTest.java
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-16.xml
- copied, changed from r1074426, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-15.xml
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-17.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesParser.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
camel/trunk/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java
camel/trunk/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java?rev=1074807&r1=1074806&r2=1074807&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java Sat Feb 26 09:24:53 2011
@@ -57,7 +57,7 @@ public class DefaultPropertiesParser imp
return answer;
}
- public String parsePropertyValue(String value) {
+ public String parseProperty(String key, String value, Properties properties) {
return value;
}
@@ -94,21 +94,21 @@ public class DefaultPropertiesParser imp
}
private String createConstantPart(String uri, int start, int end) {
- return parsePropertyValue(uri.substring(start, end));
+ return uri.substring(start, end);
}
- private String createPlaceholderPart(String placeholderPart, Properties properties, List<String> replaced) {
+ private String createPlaceholderPart(String key, Properties properties, List<String> replaced) {
// keep track of which parts we have replaced
- replaced.add(placeholderPart);
+ replaced.add(key);
- String propertyValue = System.getProperty(placeholderPart);
+ String propertyValue = System.getProperty(key);
if (propertyValue != null) {
- log.info("Found a JVM system property: " + placeholderPart + ". Overriding property set via Property Location");
- } else {
- propertyValue = properties.getProperty(placeholderPart);
+ log.debug("Found a JVM system property: {} with value: {} to be used.", key, propertyValue);
+ } else if (properties != null) {
+ propertyValue = properties.getProperty(key);
}
- return parsePropertyValue(propertyValue);
+ return parseProperty(key, propertyValue, properties);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesParser.java?rev=1074807&r1=1074806&r2=1074807&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesParser.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesParser.java Sat Feb 26 09:24:53 2011
@@ -20,13 +20,11 @@ import java.util.Properties;
/**
* A parser to parse properties for a given input
- *
- * @version
*/
public interface PropertiesParser {
/**
- * Parses the string and replaces the property placeholders with values from the given properties
+ * Parses the string and replaces the property placeholders with values from the given properties.
*
* @param text the text to be parsed
* @param properties the properties resolved which values should be looked up
@@ -38,10 +36,15 @@ public interface PropertiesParser {
String parseUri(String text, Properties properties, String prefixToken, String suffixToken) throws IllegalArgumentException;
/**
- * Parses the property value
+ * While parsing the uri using {@link #parseUri(String, java.util.Properties, String, String) parseUri} each
+ * parsed property found invokes this callback.
+ * <p/>
+ * This strategy method allows you to hook into the parsing and do custom lookup and return the actual value to use.
*
- * @param value the value
- * @return the parsed value
+ * @param key the key
+ * @param value the value
+ * @param properties the properties resolved which values should be looked up
+ * @return the value to use
*/
- String parsePropertyValue(String value);
+ String parseProperty(String key, String value, Properties properties);
}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java?rev=1074807&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java Sat Feb 26 09:24:53 2011
@@ -0,0 +1,126 @@
+/**
+ * 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.blueprint;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ExtendedBeanMetadata;
+import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
+import org.apache.camel.component.properties.DefaultPropertiesParser;
+import org.apache.camel.component.properties.PropertiesParser;
+import org.apache.camel.util.ObjectHelper;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+
+/**
+ * Blueprint {@link PropertiesParser} which supports looking up
+ * property placeholders from the Blueprint Property Placeholder Service.
+ * <p/>
+ * This implementation will sit on top of any existing configured
+ * {@link PropertiesParser} and will delegate to those in case Blueprint could not
+ * resolve the property.
+ */
+public class BlueprintPropertiesParser extends DefaultPropertiesParser {
+
+ private final BlueprintContainer container;
+ private PropertiesParser delegate;
+ private final Set<AbstractPropertyPlaceholder> placeholders = new LinkedHashSet<AbstractPropertyPlaceholder>();
+ private Method method;
+
+ public BlueprintPropertiesParser(BlueprintContainer container, PropertiesParser delegate) {
+ this.container = container;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Lookup the ids of the Blueprint property placeholder services in the
+ * Blueprint container.
+ *
+ * @return the ids, will be an empty array if none found.
+ */
+ public String[] lookupPropertyPlaceholderIds() {
+ List<String> ids = new ArrayList<String>();
+
+ for (String id : container.getComponentIds()) {
+ ComponentMetadata meta = container.getComponentMetadata(id);
+ if (meta instanceof ExtendedBeanMetadata) {
+ Class clazz = ((ExtendedBeanMetadata) meta).getRuntimeClass();
+ if (clazz != null && AbstractPropertyPlaceholder.class.isAssignableFrom(clazz)) {
+ ids.add(id);
+ }
+ }
+ }
+
+ return ids.toArray(new String[ids.size()]);
+ }
+
+ /**
+ * Adds the given Blueprint property placeholder service with the given id
+ *
+ * @param id id of the Blueprint property placeholder service to add.
+ */
+ public void addPropertyPlaceholder(String id) {
+ Object component = container.getComponentInstance(id);
+
+ if (component instanceof AbstractPropertyPlaceholder) {
+ AbstractPropertyPlaceholder placeholder = (AbstractPropertyPlaceholder) component;
+ placeholders.add(placeholder);
+
+ log.debug("Adding Blueprint PropertyPlaceholder: {}", id);
+
+ if (method == null) {
+ try {
+ method = AbstractPropertyPlaceholder.class.getDeclaredMethod("getProperty", String.class);
+ method.setAccessible(true);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Cannot add blueprint property placeholder: " + id
+ + " as the method getProperty is not accessible", e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public String parseProperty(String key, String value, Properties properties) {
+ log.trace("Parsing property key: {} with value: {}", key, value);
+
+ // lookup key in blueprint and return its value
+ if (key != null) {
+ for (AbstractPropertyPlaceholder placeholder : placeholders) {
+ value = (String) ObjectHelper.invokeMethod(method, placeholder, key);
+ if (value != null) {
+ log.debug("Blueprint parsed property key: {} as value: {}", key, value);
+ break;
+ }
+ }
+ }
+
+ if (value == null && delegate != null) {
+ // let delegate have a try since blueprint didn't resolve it
+ value = delegate.parseProperty(key, value, properties);
+ }
+
+ log.trace("Returning parsed property key: {} as value: {}", key, value);
+ return value;
+ }
+
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesResolver.java?rev=1074807&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesResolver.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesResolver.java Sat Feb 26 09:24:53 2011
@@ -0,0 +1,72 @@
+/**
+ * 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.blueprint;
+
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.properties.PropertiesResolver;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * A {@link PropertiesResolver} which supports the <tt>blueprint</tt> scheme.
+ * <p/>
+ * This implementation will sit on top of any existing configured
+ * {@link org.apache.camel.component.properties.PropertiesResolver} and will delegate
+ * to any non <tt>blueprint</tt> schemes.
+ */
+public class BlueprintPropertiesResolver implements PropertiesResolver {
+
+ private final PropertiesResolver delegate;
+ private final BlueprintPropertiesParser blueprint;
+
+ public BlueprintPropertiesResolver(PropertiesResolver delegate, BlueprintPropertiesParser blueprint) {
+ this.delegate = delegate;
+ this.blueprint = blueprint;
+ }
+
+ @Override
+ public Properties resolveProperties(CamelContext context, String... urls) throws Exception {
+ Properties answer = new Properties();
+
+ boolean explicit = false;
+
+ for (String url : urls) {
+ if (url.startsWith("blueprint:")) {
+ String ref = ObjectHelper.after(url, "blueprint:");
+ blueprint.addPropertyPlaceholder(ref);
+ // indicate an explicit blueprint id was configured
+ explicit = true;
+ } else {
+ // delegate the url
+ answer.putAll(delegate.resolveProperties(context, url));
+ }
+ }
+
+ if (!explicit) {
+ // auto lookup blueprint property placeholders to use if none explicit was configured
+ // this is convention over configuration
+ String[] ids = blueprint.lookupPropertyPlaceholderIds();
+ for (String id : ids) {
+ blueprint.addPropertyPlaceholder(id);
+ }
+ }
+
+ return answer;
+ }
+
+}
Modified: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java?rev=1074807&r1=1074806&r2=1074807&view=diff
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java Sat Feb 26 09:24:53 2011
@@ -19,7 +19,6 @@ package org.apache.camel.blueprint;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@@ -33,6 +32,7 @@ import org.apache.camel.RoutesBuilder;
import org.apache.camel.ShutdownRoute;
import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.core.osgi.OsgiCamelContextPublisher;
import org.apache.camel.core.osgi.OsgiEventAdminNotifier;
import org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader;
@@ -90,6 +90,8 @@ public class CamelContextFactoryBean ext
@XmlAttribute(required = false)
private String useMDCLogging;
@XmlAttribute(required = false)
+ private Boolean useBlueprintPropertyResolver;
+ @XmlAttribute(required = false)
private ShutdownRoute shutdownRoute;
@XmlAttribute(required = false)
private ShutdownRunningTask shutdownRunningTask;
@@ -197,6 +199,37 @@ public class CamelContextFactoryBean ext
}
@Override
+ protected void initPropertyPlaceholder() throws Exception {
+ super.initPropertyPlaceholder();
+
+ // if blueprint property resolver is enabled on CamelContext then bridge PropertiesComponent to blueprint
+ if (isUseBlueprintPropertyResolver()) {
+ // lookup existing configured properties component
+ PropertiesComponent pc = getContext().getComponent("properties", PropertiesComponent.class);
+
+ BlueprintPropertiesParser parser = new BlueprintPropertiesParser(blueprintContainer, pc.getPropertiesParser());
+ BlueprintPropertiesResolver resolver = new BlueprintPropertiesResolver(pc.getPropertiesResolver(), parser);
+
+ // no locations has been set, so its a default component
+ if (pc.getLocations() == null) {
+ StringBuilder sb = new StringBuilder();
+ String[] ids = parser.lookupPropertyPlaceholderIds();
+ for (String id : ids) {
+ sb.append("blueprint:").append(id).append(",");
+ }
+ // location supports multiple separated by comma
+ pc.setLocation(sb.toString());
+ }
+
+ if (pc.getLocations() != null) {
+ // bridge camel properties with blueprint
+ pc.setPropertiesParser(parser);
+ pc.setPropertiesResolver(resolver);
+ }
+ }
+ }
+
+ @Override
protected void initBeanPostProcessor(BlueprintCamelContext context) {
}
@@ -492,4 +525,17 @@ public class CamelContextFactoryBean ext
implicitId = flag;
}
+ public Boolean getUseBlueprintPropertyResolver() {
+ return useBlueprintPropertyResolver;
+ }
+
+ public void setUseBlueprintPropertyResolver(Boolean useBlueprintPropertyResolver) {
+ this.useBlueprintPropertyResolver = useBlueprintPropertyResolver;
+ }
+
+ public boolean isUseBlueprintPropertyResolver() {
+ // enable by default
+ return useBlueprintPropertyResolver == null || useBlueprintPropertyResolver.booleanValue();
+ }
+
}
Modified: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java?rev=1074807&r1=1074806&r2=1074807&view=diff
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java Sat Feb 26 09:24:53 2011
@@ -317,7 +317,7 @@ public abstract class AbstractCamelConte
protected abstract void initCustomRegistry(T context);
- private void initJMXAgent() throws Exception {
+ protected void initJMXAgent() throws Exception {
CamelJMXAgentDefinition camelJMXAgent = getCamelJMXAgent();
boolean disabled = false;
@@ -358,7 +358,7 @@ public abstract class AbstractCamelConte
}
}
- private void initPropertyPlaceholder() throws Exception {
+ protected void initPropertyPlaceholder() throws Exception {
if (getCamelPropertyPlaceholder() != null) {
CamelPropertyPlaceholderDefinition def = getCamelPropertyPlaceholder();
@@ -384,7 +384,7 @@ public abstract class AbstractCamelConte
}
}
- private void initRouteRefs() throws Exception {
+ protected void initRouteRefs() throws Exception {
// add route refs to existing routes
if (getRouteRefs() != null) {
for (RouteContextRefDefinition ref : getRouteRefs()) {
@@ -519,7 +519,7 @@ public abstract class AbstractCamelConte
}
}
- private void initThreadPoolProfiles(T context) {
+ protected void initThreadPoolProfiles(T context) {
Set<String> defaultIds = new HashSet<String>();
// lookup and use custom profiles from the registry
Modified: camel/trunk/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java?rev=1074807&r1=1074806&r2=1074807&view=diff
==============================================================================
--- camel/trunk/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java (original)
+++ camel/trunk/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java Sat Feb 26 09:24:53 2011
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.jasypt;
+import java.util.Properties;
+
import org.apache.camel.component.properties.DefaultPropertiesParser;
import org.apache.camel.util.ObjectHelper;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
@@ -33,7 +35,6 @@ public class JasyptPropertiesParser exte
public static final String JASYPT_PREFIX_TOKEN = "ENC(";
public static final String JASYPT_SUFFIX_TOKEN = ")";
- // TODO: A JasyptComponent we can leverage instead of directly from here
private StandardPBEStringEncryptor encryptor;
private String password;
private String algorithm;
@@ -76,7 +77,7 @@ public class JasyptPropertiesParser exte
}
@Override
- public String parsePropertyValue(String value) {
+ public String parseProperty(String key, String value, Properties properties) {
// check if the value is using the tokens
String text = ObjectHelper.between(value, JASYPT_PREFIX_TOKEN, JASYPT_SUFFIX_TOKEN);
if (text == null) {
Modified: camel/trunk/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java?rev=1074807&r1=1074806&r2=1074807&view=diff
==============================================================================
--- camel/trunk/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java (original)
+++ camel/trunk/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/JasyptPropertiesParserTest.java Sat Feb 26 09:24:53 2011
@@ -27,8 +27,8 @@ public class JasyptPropertiesParserTest
JasyptPropertiesParser parser = new JasyptPropertiesParser();
parser.setPassword("secret");
- assertEquals("foo", parser.parsePropertyValue("foo"));
- assertEquals("tiger", parser.parsePropertyValue("ENC(bsW9uV37gQ0QHFu7KO03Ww==)"));
+ assertEquals("foo", parser.parseProperty(null, "foo", null));
+ assertEquals("tiger", parser.parseProperty(null, "ENC(bsW9uV37gQ0QHFu7KO03Ww==)", null));
}
public void testJasyptPropertiesParserSys() throws Exception {
@@ -37,8 +37,8 @@ public class JasyptPropertiesParserTest
JasyptPropertiesParser parser = new JasyptPropertiesParser();
parser.setPassword("sys:myfoo");
- assertEquals("foo", parser.parsePropertyValue("foo"));
- assertEquals("tiger", parser.parsePropertyValue("ENC(bsW9uV37gQ0QHFu7KO03Ww==)"));
+ assertEquals("foo", parser.parseProperty(null, "foo", null));
+ assertEquals("tiger", parser.parseProperty(null, "ENC(bsW9uV37gQ0QHFu7KO03Ww==)", null));
System.clearProperty("myfoo");
}
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintExplicitPropertiesRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintExplicitPropertiesRouteTest.java?rev=1074807&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintExplicitPropertiesRouteTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintExplicitPropertiesRouteTest.java Sat Feb 26 09:24:53 2011
@@ -0,0 +1,103 @@
+/**
+ * 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.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+
+/**
+ *
+ */
+@RunWith(JUnit4TestRunner.class)
+public class BlueprintExplicitPropertiesRouteTest extends OSGiBlueprintTestSupport {
+
+ private String name = BlueprintExplicitPropertiesRouteTest.class.getName();
+
+ @Test
+ public void testBlueprintProperties() throws Exception {
+ // start bundle
+ getInstalledBundle(name).start();
+
+ // must use the camel context from osgi
+ CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.symbolicname=" + name + ")", 5000);
+
+ ProducerTemplate myTemplate = ctx.createProducerTemplate();
+ myTemplate.start();
+
+ // do our testing
+ MockEndpoint foo = ctx.getEndpoint("mock:foo", MockEndpoint.class);
+ foo.expectedMessageCount(1);
+ MockEndpoint result = ctx.getEndpoint("mock:result", MockEndpoint.class);
+ result.expectedMessageCount(1);
+
+ myTemplate.sendBody("direct:start", "Hello World");
+
+ foo.assertIsSatisfied();
+ result.assertIsSatisfied();
+
+ myTemplate.stop();
+ }
+
+ @Configuration
+ public static Option[] configure() throws Exception {
+
+ Option[] options = options(
+
+ bundle(newBundle()
+ .add("OSGI-INF/blueprint/test.xml", BlueprintExplicitPropertiesRouteTest.class.getResource("blueprint-16.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME, BlueprintExplicitPropertiesRouteTest.class.getName())
+ .build()).noStart(),
+
+ // install the spring dm profile
+ profile("spring.dm").version("1.2.0"),
+ // this is how you set the default log level when using pax logging (logProfile)
+ // org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("TRACE"),
+
+ // install blueprint requirements
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // install tiny bundles
+ mavenBundle("org.ops4j.base", "ops4j-base-store"),
+ wrappedBundle(mavenBundle("org.ops4j.pax.swissbox", "pax-swissbox-bnd")),
+ mavenBundle("org.ops4j.pax.swissbox", "pax-swissbox-tinybundles"),
+
+ // using the features to install the camel components
+ scanFeatures(getCamelKarafFeatureUrl(),
+ "camel-core", "camel-blueprint", "camel-test"),
+
+ workingDirectory("target/paxrunner/"),
+
+ felix()/*, equinox()*/);
+
+ return options;
+ }
+
+}
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintPropertiesRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintPropertiesRouteTest.java?rev=1074807&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintPropertiesRouteTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/BlueprintPropertiesRouteTest.java Sat Feb 26 09:24:53 2011
@@ -0,0 +1,103 @@
+/**
+ * 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.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+
+/**
+ *
+ */
+@RunWith(JUnit4TestRunner.class)
+public class BlueprintPropertiesRouteTest extends OSGiBlueprintTestSupport {
+
+ private String name = BlueprintPropertiesRouteTest.class.getName();
+
+ @Test
+ public void testBlueprintProperties() throws Exception {
+ // start bundle
+ getInstalledBundle(name).start();
+
+ // must use the camel context from osgi
+ CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.symbolicname=" + name + ")", 5000);
+
+ ProducerTemplate myTemplate = ctx.createProducerTemplate();
+ myTemplate.start();
+
+ // do our testing
+ MockEndpoint foo = ctx.getEndpoint("mock:foo", MockEndpoint.class);
+ foo.expectedMessageCount(1);
+ MockEndpoint result = ctx.getEndpoint("mock:result", MockEndpoint.class);
+ result.expectedMessageCount(1);
+
+ myTemplate.sendBody("direct:start", "Hello World");
+
+ foo.assertIsSatisfied();
+ result.assertIsSatisfied();
+
+ myTemplate.stop();
+ }
+
+ @Configuration
+ public static Option[] configure() throws Exception {
+
+ Option[] options = options(
+
+ bundle(newBundle()
+ .add("OSGI-INF/blueprint/test.xml", BlueprintPropertiesRouteTest.class.getResource("blueprint-17.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME, BlueprintPropertiesRouteTest.class.getName())
+ .build()).noStart(),
+
+ // install the spring dm profile
+ profile("spring.dm").version("1.2.0"),
+ // this is how you set the default log level when using pax logging (logProfile)
+ // org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("TRACE"),
+
+ // install blueprint requirements
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // install tiny bundles
+ mavenBundle("org.ops4j.base", "ops4j-base-store"),
+ wrappedBundle(mavenBundle("org.ops4j.pax.swissbox", "pax-swissbox-bnd")),
+ mavenBundle("org.ops4j.pax.swissbox", "pax-swissbox-tinybundles"),
+
+ // using the features to install the camel components
+ scanFeatures(getCamelKarafFeatureUrl(),
+ "camel-core", "camel-blueprint", "camel-test"),
+
+ workingDirectory("target/paxrunner/"),
+
+ felix()/*, equinox()*/);
+
+ return options;
+ }
+
+}
Copied: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-16.xml (from r1074426, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-15.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-16.xml?p2=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-16.xml&p1=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-15.xml&r1=1074426&r2=1074807&rev=1074807&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-15.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-16.xml Sat Feb 26 09:24:53 2011
@@ -15,15 +15,34 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+<!-- 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">
+ <!-- list some properties for this test -->
+ <cm:default-properties>
+ <cm:property name="result" value="mock:result"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <!-- using Camel properties component and refer to the blueprint property placeholder by its id -->
+ <propertyPlaceholder id="properties" location="blueprint:myblueprint.placeholder"/>
+
+ <!-- in the route we can use {{ }} placeholders which will lookup in blueprint -->
<route>
- <from uri="mycomp:queue"/>
- <to uri="mock:result"/>
+ <from uri="direct:start"/>
+ <to uri="mock:foo"/>
+ <to uri="{{result}}"/>
</route>
- </camelContext>
- <bean id="mycomp" class="org.apache.camel.component.seda.SedaComponent"/>
+ </camelContext>
</blueprint>
+<!-- END SNIPPET: e1 -->
Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-17.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-17.xml?rev=1074807&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-17.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-17.xml Sat Feb 26 09:24:53 2011
@@ -0,0 +1,46 @@
+<?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">
+ <!-- list some properties for this test -->
+ <cm:default-properties>
+ <cm:property name="result" value="mock:result"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <!-- 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="{{result}}"/>
+ </route>
+
+ </camelContext>
+
+</blueprint>
+<!-- END SNIPPET: e1 -->