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 2014/12/03 09:23:39 UTC
[1/5] camel git commit: CAMEL-8107: Allow to use property placeholder
with default values without having to setup the properties component
Repository: camel
Updated Branches:
refs/heads/camel-2.14.x 279b7f3d0 -> 48a75fa38
CAMEL-8107: Allow to use property placeholder with default values without having to setup the properties component
Conflicts:
camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3beb8e2d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3beb8e2d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3beb8e2d
Branch: refs/heads/camel-2.14.x
Commit: 3beb8e2dbbabae82eac78894723c469dd0e1e223
Parents: 279b7f3
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 2 20:17:56 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 08:53:34 2014 +0100
----------------------------------------------------------------------
.../properties/DefaultPropertiesParser.java | 27 ++++++-
.../properties/PropertiesComponent.java | 9 ++-
.../apache/camel/impl/DefaultCamelContext.java | 22 ++---
.../PropertiesComponentEndpointTest.java | 3 +-
...ertiesComponentOnlyUseDefaultValuesTest.java | 85 ++++++++++++++++++++
5 files changed, 130 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3beb8e2d/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index 6a5b80f..137c6c1 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -26,15 +26,32 @@ import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
- * A parser to parse a string which contains property placeholders
+ * A parser to parse a string which contains property placeholders.
*/
public class DefaultPropertiesParser implements AugmentedPropertyNameAwarePropertiesParser {
- protected final Logger log = LoggerFactory.getLogger(getClass());
private static final String GET_OR_ELSE_TOKEN = ":";
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ private PropertiesComponent propertiesComponent;
+
+ public DefaultPropertiesParser() {
+ }
+
+ public DefaultPropertiesParser(PropertiesComponent propertiesComponent) {
+ this.propertiesComponent = propertiesComponent;
+ }
+
+ public PropertiesComponent getPropertiesComponent() {
+ return propertiesComponent;
+ }
+
+ public void setPropertiesComponent(PropertiesComponent propertiesComponent) {
+ this.propertiesComponent = propertiesComponent;
+ }
+
@Override
public String parseUri(String text, Properties properties, String prefixToken, String suffixToken) throws IllegalArgumentException {
return parseUri(text, properties, prefixToken, suffixToken, null, null, false);
@@ -215,6 +232,10 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper
if (value == null) {
StringBuilder esb = new StringBuilder();
+ if (propertiesComponent.isDefaultCreated()) {
+ // if the component was auto created then include more information that the end user should define it
+ esb.append("PropertiesComponent with name properties must be defined in CamelContext to support property placeholders. ");
+ }
esb.append("Property with key [").append(augmentedKey).append("] ");
if (shouldFallback) {
esb.append("(and original key [").append(key).append("]) ");
http://git-wip-us.apache.org/repos/asf/camel/blob/3beb8e2d/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 31162fc..fec14a7 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -71,7 +71,7 @@ public class PropertiesComponent extends DefaultComponent {
private static final Logger LOG = LoggerFactory.getLogger(PropertiesComponent.class);
private final Map<CacheKey, Properties> cacheMap = new LRUSoftCache<CacheKey, Properties>(1000);
private PropertiesResolver propertiesResolver = new DefaultPropertiesResolver();
- private PropertiesParser propertiesParser = new DefaultPropertiesParser();
+ private PropertiesParser propertiesParser = new DefaultPropertiesParser(this);
private String[] locations;
private boolean ignoreMissingLocation;
private boolean cache = true;
@@ -173,6 +173,13 @@ public class PropertiesComponent extends DefaultComponent {
}
}
+ /**
+ * Is this component created as a default by {@link org.apache.camel.CamelContext} during starting up Camel.
+ */
+ public boolean isDefaultCreated() {
+ return locations == null;
+ }
+
public String[] getLocations() {
return locations;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3beb8e2d/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 1645fd8..bdc3bd4 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -36,7 +36,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-
import javax.naming.Context;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -145,6 +144,11 @@ import org.apache.camel.util.TimeUtils;
import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+<<<<<<< HEAD
+=======
+
+import static org.apache.camel.util.StringQuoteHelper.doubleQuote;
+>>>>>>> d00b08d... CAMEL-8107: Allow to use property placeholder with default values without having to setup the properties component
/**
* Represents the context used to configure routes and the policies to use.
@@ -1269,18 +1273,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
}
- if (pc != null) {
- // the parser will throw exception if property key was not found
- String answer = pc.parseUri(text);
- log.debug("Resolved text: {} -> {}", text, answer);
- return answer;
- } else {
- throw new IllegalArgumentException("PropertiesComponent with name properties must be defined"
- + " in CamelContext to support property placeholders.");
+ if (pc == null) {
+ // create a default properties component to be used as there may be default values we can use
+ log.info("No existing PropertiesComponent has been configured, creating a new default PropertiesComponent with name: properties");
+ pc = getComponent("properties", PropertiesComponent.class);
}
+ }
- // Component available, use actual tokens
- } else if (pc != null && text.contains(pc.getPrefixToken())) {
+ if (pc != null && text.contains(pc.getPrefixToken())) {
// the parser will throw exception if property key was not found
String answer = pc.parseUri(text);
log.debug("Resolved text: {} -> {}", text, answer);
http://git-wip-us.apache.org/repos/asf/camel/blob/3beb8e2d/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java
index 47a39c3..557008f 100644
--- a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java
@@ -82,7 +82,8 @@ public class PropertiesComponentEndpointTest extends ContextTestSupport {
} catch (FailedToCreateRouteException e) {
ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
- assertEquals("PropertiesComponent with name properties must be defined in CamelContext to support property placeholders.", iae.getMessage());
+ String msg = "PropertiesComponent with name properties must be defined in CamelContext to support property placeholders.";
+ assertTrue(iae.getMessage().startsWith(msg));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3beb8e2d/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java
new file mode 100644
index 0000000..2bb8e51
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java
@@ -0,0 +1,85 @@
+/**
+ * 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.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentOnlyUseDefaultValuesTest extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testOnlyDefaults() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("{{foo:mock:foo}}")
+ .to("{{bar:mock:bar}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testOneMissing() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("{{foo:mock:foo}}")
+ .to("{{bar}}");
+ }
+ });
+
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToCreateRouteException e) {
+ // expected
+ }
+ }
+
+ public void testAllMissing() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("{{foo:mock:foo}}")
+ .to("{{bar}}");
+ }
+ });
+
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToCreateRouteException e) {
+ // expected
+ }
+ }
+
+}
[2/5] camel git commit: CAMEL-8109: Allow to plugin custom functions
to property placeholder
Posted by da...@apache.org.
CAMEL-8109: Allow to plugin custom functions to property placeholder
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7be7d574
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7be7d574
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7be7d574
Branch: refs/heads/camel-2.14.x
Commit: 7be7d574d5e68d9d28edad0c9eea7c39d26dc216
Parents: 3beb8e2
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 2 20:56:03 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 08:54:04 2014 +0100
----------------------------------------------------------------------
.../properties/DefaultPropertiesParser.java | 17 +++++-
.../properties/PropertiesComponent.java | 18 +++++-
.../properties/PropertiesFunction.java | 37 +++++++++++
.../PropertiesComponentFunctionTest.java | 64 ++++++++++++++++++++
4 files changed, 133 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7be7d574/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index 137c6c1..ecc3ac6 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -20,12 +20,12 @@ import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
-import static java.lang.String.format;
-
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static java.lang.String.format;
+
/**
* A parser to parse a string which contains property placeholders.
*/
@@ -209,6 +209,19 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper
* @return Value of the property with the given key
*/
private String getPropertyValue(String key, String input) {
+
+ // the key may be a function, so lets check this first
+ if (propertiesComponent != null) {
+ for (PropertiesFunction function : propertiesComponent.getFunctions().values()) {
+ String token = function.getName() + ":";
+ if (key.startsWith(token)) {
+ String remainder = key.substring(token.length());
+ log.debug("Property with key [{}] is applied by function [{}]", key, function.getName());
+ return function.apply(remainder);
+ }
+ }
+ }
+
// they key may have a get or else expression
String defaultValue = null;
if (key.contains(GET_OR_ELSE_TOKEN)) {
http://git-wip-us.apache.org/repos/asf/camel/blob/7be7d574/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index fec14a7..30692b0 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.properties;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -70,6 +71,7 @@ public class PropertiesComponent extends DefaultComponent {
private static final Logger LOG = LoggerFactory.getLogger(PropertiesComponent.class);
private final Map<CacheKey, Properties> cacheMap = new LRUSoftCache<CacheKey, Properties>(1000);
+ private final Map<String, PropertiesFunction> functions = new HashMap<String, PropertiesFunction>();
private PropertiesResolver propertiesResolver = new DefaultPropertiesResolver();
private PropertiesParser propertiesParser = new DefaultPropertiesParser(this);
private String[] locations;
@@ -84,7 +86,7 @@ public class PropertiesComponent extends DefaultComponent {
private String suffixToken = DEFAULT_SUFFIX_TOKEN;
private Properties initialProperties;
private Properties overrideProperties;
-
+
public PropertiesComponent() {
}
@@ -315,6 +317,20 @@ public class PropertiesComponent extends DefaultComponent {
this.overrideProperties = overrideProperties;
}
+ /**
+ * Gets the functions registered in this properties component.
+ */
+ public Map<String, PropertiesFunction> getFunctions() {
+ return functions;
+ }
+
+ /**
+ * Add the function
+ */
+ public void addFunction(PropertiesFunction function) {
+ this.functions.put(function.getName(), function);
+ }
+
@Override
protected void doStop() throws Exception {
cacheMap.clear();
http://git-wip-us.apache.org/repos/asf/camel/blob/7be7d574/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesFunction.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesFunction.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesFunction.java
new file mode 100644
index 0000000..25bb724
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesFunction.java
@@ -0,0 +1,37 @@
+/**
+ * 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.properties;
+
+/**
+ * A function that is applied instead of looking up a property placeholder.
+ */
+public interface PropertiesFunction {
+
+ /**
+ * Name of the function which is used as <tt>name:</tt> to let the properties component know its a function.
+ */
+ String getName();
+
+ /**
+ * Applies the function
+ *
+ * @param remainder the remainder value
+ * @return a value as the result of the function
+ */
+ String apply(String remainder);
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/7be7d574/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
new file mode 100644
index 0000000..4213cd0
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesComponentFunctionTest extends ContextTestSupport {
+
+ private class MyFunction implements PropertiesFunction {
+
+ @Override
+ public String getName() {
+ return "beer";
+ }
+
+ @Override
+ public String apply(String remainder) {
+ return "mock:" + remainder.toLowerCase();
+ }
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testFunction() throws Exception {
+ PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+ pc.addFunction(new MyFunction());
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("{{beer:FOO}}")
+ .to("{{beer:BAR}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
[5/5] camel git commit: CAMEL-8107: Fixed merge
Posted by da...@apache.org.
CAMEL-8107: Fixed merge
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/48a75fa3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/48a75fa3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/48a75fa3
Branch: refs/heads/camel-2.14.x
Commit: 48a75fa38ad62453ae01c34988cd5828ff834f77
Parents: 74821fd
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 3 08:58:16 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 08:58:16 2014 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/impl/DefaultCamelContext.java | 3 ---
1 file changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/48a75fa3/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index bdc3bd4..6fcc4fa 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -144,11 +144,8 @@ import org.apache.camel.util.TimeUtils;
import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-<<<<<<< HEAD
-=======
import static org.apache.camel.util.StringQuoteHelper.doubleQuote;
->>>>>>> d00b08d... CAMEL-8107: Allow to use property placeholder with default values without having to setup the properties component
/**
* Represents the context used to configure routes and the policies to use.
[4/5] camel git commit: CAMEL-8107: Allow to use property placeholder
with default values without having to setup the properties component
Posted by da...@apache.org.
CAMEL-8107: Allow to use property placeholder with default values without having to setup the properties component
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/74821fda
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/74821fda
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/74821fda
Branch: refs/heads/camel-2.14.x
Commit: 74821fdafbd393d9a6bdbcda142f5e05e3883d32
Parents: 869f1b5
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 3 07:34:36 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 08:54:16 2014 +0100
----------------------------------------------------------------------
.../camel/component/properties/PropertiesComponent.java | 10 ++++++++++
.../cdi/component/properties/CdiPropertiesComponent.java | 2 +-
.../cdi/component/properties/CdiPropertiesParser.java | 5 +++++
3 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/74821fda/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index e30fb03..247c357 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -339,6 +339,16 @@ public class PropertiesComponent extends DefaultComponent {
}
@Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ // inject the component to the parser
+ if (propertiesParser instanceof DefaultPropertiesParser) {
+ ((DefaultPropertiesParser) propertiesParser).setPropertiesComponent(this);
+ }
+ }
+
+ @Override
protected void doStop() throws Exception {
cacheMap.clear();
functions.clear();
http://git-wip-us.apache.org/repos/asf/camel/blob/74821fda/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java
index dd0b3f6..921f6a1 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesComponent.java
@@ -27,7 +27,7 @@ import org.apache.camel.component.properties.PropertiesComponent;
public class CdiPropertiesComponent extends PropertiesComponent {
public CdiPropertiesComponent() {
- setPropertiesParser(new CdiPropertiesParser());
+ setPropertiesParser(new CdiPropertiesParser(this));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/74821fda/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java
index 332b7f6..e9cde59 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/component/properties/CdiPropertiesParser.java
@@ -19,6 +19,7 @@ package org.apache.camel.cdi.component.properties;
import java.util.Properties;
import org.apache.camel.component.properties.DefaultPropertiesParser;
+import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.deltaspike.core.api.config.ConfigResolver;
/**
@@ -28,6 +29,10 @@ import org.apache.deltaspike.core.api.config.ConfigResolver;
*/
public class CdiPropertiesParser extends DefaultPropertiesParser {
+ public CdiPropertiesParser(PropertiesComponent propertiesComponent) {
+ super(propertiesComponent);
+ }
+
@Override
public String parseProperty(String key, String value, Properties properties) {
String answer = ConfigResolver.getPropertyValue(key);
[3/5] camel git commit: CAMEL-8109: Allow to plugin custom functions
to property placeholder
Posted by da...@apache.org.
CAMEL-8109: Allow to plugin custom functions to property placeholder
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/869f1b52
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/869f1b52
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/869f1b52
Branch: refs/heads/camel-2.14.x
Commit: 869f1b52ff7c4b7d07028457af3e851ed9baedd1
Parents: 7be7d57
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 2 22:13:16 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 08:54:10 2014 +0100
----------------------------------------------------------------------
.../properties/PropertiesComponent.java | 10 +++-
.../PropertiesComponentFunctionTest.java | 2 +-
.../blueprint/BlueprintPropertiesParser.java | 1 +
.../handler/CamelNamespaceHandler.java | 6 +++
.../xml/AbstractCamelContextFactoryBean.java | 10 +++-
.../xml/CamelPropertyPlaceholderDefinition.java | 13 +++++
...elPropertyPlaceholderFunctionDefinition.java | 37 ++++++++++++++
.../SpringPropertiesComponentFunctionTest.java | 54 ++++++++++++++++++++
.../SpringPropertiesComponentFunctionTest.xml | 40 +++++++++++++++
.../PropertiesComponentFunctionTest.java | 53 +++++++++++++++++++
.../PropertiesComponentFunctionTest.xml | 41 +++++++++++++++
11 files changed, 264 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 30692b0..e30fb03 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -325,15 +325,23 @@ public class PropertiesComponent extends DefaultComponent {
}
/**
- * Add the function
+ * Registers the {@link org.apache.camel.component.properties.PropertiesFunction} as a function to this component.
*/
public void addFunction(PropertiesFunction function) {
this.functions.put(function.getName(), function);
}
+ /**
+ * Is there a {@link org.apache.camel.component.properties.PropertiesFunction} with the given name?
+ */
+ public boolean hasFunction(String name) {
+ return functions.containsKey(name);
+ }
+
@Override
protected void doStop() throws Exception {
cacheMap.clear();
+ functions.clear();
super.doStop();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
index 4213cd0..f960f6d 100644
--- a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.builder.RouteBuilder;
public class PropertiesComponentFunctionTest extends ContextTestSupport {
- private class MyFunction implements PropertiesFunction {
+ public static final class MyFunction implements PropertiesFunction {
@Override
public String getName() {
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
index 9c5a3f0..efc5347 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
@@ -51,6 +51,7 @@ public class BlueprintPropertiesParser extends DefaultPropertiesParser {
private Method method;
public BlueprintPropertiesParser(PropertiesComponent propertiesComponent, BlueprintContainer container, PropertiesParser delegate) {
+ super(propertiesComponent);
this.propertiesComponent = propertiesComponent;
this.container = container;
this.delegate = delegate;
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
index 4985abc..eab8798 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
@@ -33,6 +33,7 @@ import javax.xml.bind.Binder;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
+import org.apache.camel.component.properties.PropertiesComponent;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -1041,6 +1042,11 @@ public class CamelNamespaceHandler implements NamespaceHandler {
}
private void findUriComponent(String uri, Set<String> components) {
+ // if the uri is a placeholder then skip it
+ if (uri != null && uri.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) {
+ return;
+ }
+
if (uri != null) {
String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 2);
if (splitURI[1] != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index f960c3a..32b84a8 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -24,7 +24,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlTransient;
@@ -38,6 +37,7 @@ import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.component.properties.PropertiesFunction;
import org.apache.camel.component.properties.PropertiesParser;
import org.apache.camel.component.properties.PropertiesResolver;
import org.apache.camel.management.DefaultManagementAgent;
@@ -535,6 +535,14 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
pc.setPrefixToken(def.getPrefixToken());
pc.setSuffixToken(def.getSuffixToken());
+ if (def.getFunctions() != null && !def.getFunctions().isEmpty()) {
+ for (CamelPropertyPlaceholderFunctionDefinition function : def.getFunctions()) {
+ String ref = function.getRef();
+ PropertiesFunction pf = CamelContextHelper.mandatoryLookup(getContext(), ref, PropertiesFunction.class);
+ pc.addFunction(pf);
+ }
+ }
+
// register the properties component
getContext().addComponent("properties", pc);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java
index 17d2276..cc61c2f 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java
@@ -16,9 +16,11 @@
*/
package org.apache.camel.core.xml;
+import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.model.IdentifiedType;
@@ -62,6 +64,9 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType {
@XmlAttribute
private String suffixToken;
+ @XmlElement(name = "propertiesFunction")
+ private List<CamelPropertyPlaceholderFunctionDefinition> functions;
+
public String getLocation() {
return location;
}
@@ -141,4 +146,12 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType {
public void setSuffixToken(String suffixToken) {
this.suffixToken = suffixToken;
}
+
+ public List<CamelPropertyPlaceholderFunctionDefinition> getFunctions() {
+ return functions;
+ }
+
+ public void setFunctions(List<CamelPropertyPlaceholderFunctionDefinition> functions) {
+ this.functions = functions;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderFunctionDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderFunctionDefinition.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderFunctionDefinition.java
new file mode 100644
index 0000000..a7e328d
--- /dev/null
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderFunctionDefinition.java
@@ -0,0 +1,37 @@
+/**
+ * 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.core.xml;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+@XmlRootElement(name = "propertiesFunction")
+public class CamelPropertyPlaceholderFunctionDefinition extends IdentifiedType {
+
+ @XmlAttribute(required = true)
+ private String ref;
+
+ public String getRef() {
+ return ref;
+ }
+
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.java
new file mode 100644
index 0000000..c5e36a8
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.properties;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringPropertiesComponentFunctionTest extends SpringTestSupport {
+
+ public static final class MyFunction implements PropertiesFunction {
+
+ @Override
+ public String getName() {
+ return "beer";
+ }
+
+ @Override
+ public String apply(String remainder) {
+ return "mock:" + remainder.toLowerCase();
+ }
+ }
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.xml");
+ }
+
+ @Test
+ public void testFunction() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.xml
new file mode 100644
index 0000000..8d6e865
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponentFunctionTest.xml
@@ -0,0 +1,40 @@
+<?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
+ ">
+
+ <bean id="beerFunction" class="org.apache.camel.component.properties.PropertiesComponentFunctionTest.MyFunction"/>
+
+ <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+
+ <propertyPlaceholder id="properties" location="none" ignoreMissingLocation="true">
+ <propertiesFunction ref="beerFunction"/>
+ </propertyPlaceholder>
+
+ <route>
+ <from uri="direct:start"/>
+ <to uri="{{beer:FOO}}"/>
+ <to uri="{{beer:BAR}}"/>
+ </route>
+ </camelContext>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.java
new file mode 100644
index 0000000..ee39d10
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.test.blueprint;
+
+import org.apache.camel.component.properties.PropertiesFunction;
+import org.junit.Test;
+
+public class PropertiesComponentFunctionTest extends CamelBlueprintTestSupport {
+
+ public static final class MyFunction implements PropertiesFunction {
+
+ @Override
+ public String getName() {
+ return "beer";
+ }
+
+ @Override
+ public String apply(String remainder) {
+ return "mock:" + remainder.toLowerCase();
+ }
+ }
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.xml";
+ }
+
+ @Test
+ public void testFunction() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/869f1b52/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.xml
new file mode 100644
index 0000000..d2cba08
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/PropertiesComponentFunctionTest.xml
@@ -0,0 +1,41 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <bean id="beerFunction" class="org.apache.camel.test.blueprint.PropertiesComponentFunctionTest.MyFunction"/>
+
+ <bean id="vmProperties" class="org.apache.camel.test.blueprint.MyProperties" />
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <propertyPlaceholder id="properties" location="ref:vmProperties" ignoreMissingLocation="true">
+ <propertiesFunction ref="beerFunction"/>
+ </propertyPlaceholder>
+
+ <route>
+ <from uri="direct:start"/>
+ <to uri="{{beer:FOO}}"/>
+ <to uri="{{beer:BAR}}"/>
+ </route>
+ </camelContext>
+
+</blueprint>
+