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 2013/09/04 14:48:16 UTC
[1/2] git commit: CAMEL-6706: camel-blueprint property placeholder
favors non-default values when 2+ blueprint placeholders is in use for the
same key. Allows end users to override default values to be used by Camel.
Updated Branches:
refs/heads/camel-2.12.x 39354f96d -> 260ce9e35
refs/heads/master 34f4174b1 -> 68d0cb1cf
CAMEL-6706: camel-blueprint property placeholder favors non-default values when 2+ blueprint placeholders is in use for the same key. Allows end users to override default values to be used by Camel.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/68d0cb1c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/68d0cb1c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/68d0cb1c
Branch: refs/heads/master
Commit: 68d0cb1cf41592d7597f9fc424fce98f4108787b
Parents: 34f4174
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Sep 4 14:47:39 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Sep 4 14:47:39 2013 +0200
----------------------------------------------------------------------
.../blueprint/BlueprintPropertiesParser.java | 25 ++++++--
.../test/blueprint/ConfigAdminExtFileTest.java | 42 ++++++++++++
.../src/test/resources/etc/framework.properties | 19 ++++++
.../test/blueprint/ConfigAdminExtFileTest.xml | 67 ++++++++++++++++++++
4 files changed, 149 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/68d0cb1c/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 e746727..1649501 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
@@ -25,6 +25,7 @@ import java.util.Set;
import org.apache.aries.blueprint.ExtendedBeanMetadata;
import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
+import org.apache.aries.blueprint.ext.PropertyPlaceholder;
import org.apache.camel.component.properties.DefaultPropertiesParser;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.component.properties.PropertiesParser;
@@ -120,12 +121,28 @@ public class BlueprintPropertiesParser extends DefaultPropertiesParser {
// lookup key in blueprint and return its value
if (answer == null && key != null) {
for (AbstractPropertyPlaceholder placeholder : placeholders) {
- answer = (String) ObjectHelper.invokeMethod(method, placeholder, key);
- if (answer != null) {
- log.debug("Blueprint parsed property key: {} as value: {}", key, answer);
- break;
+
+ boolean isDefault = false;
+ if (placeholders.size() > 1) {
+ // okay we have multiple placeholders and we want to return the answer that
+ // is not the default placeholder if there is multiple keys
+ if (placeholder instanceof PropertyPlaceholder) {
+ isDefault = ((PropertyPlaceholder) placeholder).getDefaultProperties().containsKey(key);
+ }
+ log.trace("Blueprint property key: {} is part of default properties: {}", key, isDefault);
+ }
+
+ String candidate = (String) ObjectHelper.invokeMethod(method, placeholder, key);
+
+ if (candidate != null) {
+ if (answer == null || !isDefault) {
+ log.trace("Blueprint parsed candidate property key: {} as value: {}", key, answer);
+ answer = candidate;
+ }
}
}
+
+ log.debug("Blueprint parsed property key: {} as value: {}", key, answer);
}
// if there is a delegate then let it parse the current answer as it may be jasypt which
http://git-wip-us.apache.org/repos/asf/camel/blob/68d0cb1c/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java
new file mode 100644
index 0000000..9325d7c
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.junit.Test;
+
+/**
+ *
+ */
+public class ConfigAdminExtFileTest extends CamelBlueprintTestSupport {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml";
+ }
+
+ @Test
+ public void testConfigAdmin() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Camel World");
+
+ template.sendBody("direct:start", "World");
+
+ assertMockEndpointsSatisfied();
+
+ assertFalse("Message history should be disabled", context.isMessageHistory());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/68d0cb1c/components/camel-test-blueprint/src/test/resources/etc/framework.properties
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/etc/framework.properties b/components/camel-test-blueprint/src/test/resources/etc/framework.properties
new file mode 100644
index 0000000..c6d1c18
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/etc/framework.properties
@@ -0,0 +1,19 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+my.greeting=Camel
+my.context.messageHistory=false
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/68d0cb1c/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml
new file mode 100644
index 0000000..087ca59
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml
@@ -0,0 +1,67 @@
+<?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"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ xsi:schemaLocation="
+ http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- in this example we have 2 blueprint property placeholders -->
+ <!-- Camel 2.12.1 onwards will favor placeholders from the last defined placeholders,
+ and also favor non-default placeholders values
+ (= meaning that when overriding default values then Camel uses them instead)
+ -->
+
+ <!-- a default placeholder to setup the file locations and some default values -->
+ <cm:property-placeholder persistent-id="stuff" placeholder-prefix="{{" placeholder-suffix="}}">
+ <cm:default-properties>
+ <cm:property name="my.resources.config.folder" value="src/test/resources"/>
+ <cm:property name="my.resources.config.file" value="framework.properties"/>
+ <!-- default value is true -->
+ <!-- but we override this value in framework.properties where we set it to false -->
+ <cm:property name="my.context.messageHistory" value="true"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <!-- extended placeholder that loads the file and have additional properties -->
+ <ext:property-placeholder id="my-blueprint-placeholder">
+ <ext:default-properties>
+ <ext:property name="my-version" value="framework_1.0"/>
+ </ext:default-properties>
+ <!-- define location of properties file -->
+ <ext:location>file:{{my.resources.config.folder}}/etc/{{my.resources.config.file}}</ext:location>
+ </ext:property-placeholder>
+
+ <!-- a bean that uses a blueprint property placeholder -->
+ <bean id="myCoolBean" class="org.apache.camel.test.blueprint.MyCoolBean">
+ <property name="say" value="${my.greeting}"/>
+ </bean>
+
+ <camelContext messageHistory="{{my.context.messageHistory}}" xmlns="http://camel.apache.org/schema/blueprint">
+
+ <route>
+ <from uri="direct:start"/>
+ <bean ref="myCoolBean" method="saySomething"/>
+ <to uri="mock:result"/>
+ </route>
+
+ </camelContext>
+
+</blueprint>
[2/2] git commit: CAMEL-6706: camel-blueprint property placeholder
favors non-default values when 2+ blueprint placeholders is in use for the
same key. Allows end users to override default values to be used by Camel.
Posted by da...@apache.org.
CAMEL-6706: camel-blueprint property placeholder favors non-default values when 2+ blueprint placeholders is in use for the same key. Allows end users to override default values to be used by Camel.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/260ce9e3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/260ce9e3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/260ce9e3
Branch: refs/heads/camel-2.12.x
Commit: 260ce9e35162aeb36c87861ae444e5243a9695eb
Parents: 39354f9
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Sep 4 14:47:39 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Sep 4 14:47:58 2013 +0200
----------------------------------------------------------------------
.../blueprint/BlueprintPropertiesParser.java | 25 ++++++--
.../test/blueprint/ConfigAdminExtFileTest.java | 42 ++++++++++++
.../src/test/resources/etc/framework.properties | 19 ++++++
.../test/blueprint/ConfigAdminExtFileTest.xml | 67 ++++++++++++++++++++
4 files changed, 149 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/260ce9e3/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 e746727..1649501 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
@@ -25,6 +25,7 @@ import java.util.Set;
import org.apache.aries.blueprint.ExtendedBeanMetadata;
import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
+import org.apache.aries.blueprint.ext.PropertyPlaceholder;
import org.apache.camel.component.properties.DefaultPropertiesParser;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.component.properties.PropertiesParser;
@@ -120,12 +121,28 @@ public class BlueprintPropertiesParser extends DefaultPropertiesParser {
// lookup key in blueprint and return its value
if (answer == null && key != null) {
for (AbstractPropertyPlaceholder placeholder : placeholders) {
- answer = (String) ObjectHelper.invokeMethod(method, placeholder, key);
- if (answer != null) {
- log.debug("Blueprint parsed property key: {} as value: {}", key, answer);
- break;
+
+ boolean isDefault = false;
+ if (placeholders.size() > 1) {
+ // okay we have multiple placeholders and we want to return the answer that
+ // is not the default placeholder if there is multiple keys
+ if (placeholder instanceof PropertyPlaceholder) {
+ isDefault = ((PropertyPlaceholder) placeholder).getDefaultProperties().containsKey(key);
+ }
+ log.trace("Blueprint property key: {} is part of default properties: {}", key, isDefault);
+ }
+
+ String candidate = (String) ObjectHelper.invokeMethod(method, placeholder, key);
+
+ if (candidate != null) {
+ if (answer == null || !isDefault) {
+ log.trace("Blueprint parsed candidate property key: {} as value: {}", key, answer);
+ answer = candidate;
+ }
}
}
+
+ log.debug("Blueprint parsed property key: {} as value: {}", key, answer);
}
// if there is a delegate then let it parse the current answer as it may be jasypt which
http://git-wip-us.apache.org/repos/asf/camel/blob/260ce9e3/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java
new file mode 100644
index 0000000..9325d7c
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.junit.Test;
+
+/**
+ *
+ */
+public class ConfigAdminExtFileTest extends CamelBlueprintTestSupport {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml";
+ }
+
+ @Test
+ public void testConfigAdmin() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Camel World");
+
+ template.sendBody("direct:start", "World");
+
+ assertMockEndpointsSatisfied();
+
+ assertFalse("Message history should be disabled", context.isMessageHistory());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/260ce9e3/components/camel-test-blueprint/src/test/resources/etc/framework.properties
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/etc/framework.properties b/components/camel-test-blueprint/src/test/resources/etc/framework.properties
new file mode 100644
index 0000000..c6d1c18
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/etc/framework.properties
@@ -0,0 +1,19 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+my.greeting=Camel
+my.context.messageHistory=false
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/260ce9e3/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml
new file mode 100644
index 0000000..087ca59
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/ConfigAdminExtFileTest.xml
@@ -0,0 +1,67 @@
+<?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"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ xsi:schemaLocation="
+ http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- in this example we have 2 blueprint property placeholders -->
+ <!-- Camel 2.12.1 onwards will favor placeholders from the last defined placeholders,
+ and also favor non-default placeholders values
+ (= meaning that when overriding default values then Camel uses them instead)
+ -->
+
+ <!-- a default placeholder to setup the file locations and some default values -->
+ <cm:property-placeholder persistent-id="stuff" placeholder-prefix="{{" placeholder-suffix="}}">
+ <cm:default-properties>
+ <cm:property name="my.resources.config.folder" value="src/test/resources"/>
+ <cm:property name="my.resources.config.file" value="framework.properties"/>
+ <!-- default value is true -->
+ <!-- but we override this value in framework.properties where we set it to false -->
+ <cm:property name="my.context.messageHistory" value="true"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <!-- extended placeholder that loads the file and have additional properties -->
+ <ext:property-placeholder id="my-blueprint-placeholder">
+ <ext:default-properties>
+ <ext:property name="my-version" value="framework_1.0"/>
+ </ext:default-properties>
+ <!-- define location of properties file -->
+ <ext:location>file:{{my.resources.config.folder}}/etc/{{my.resources.config.file}}</ext:location>
+ </ext:property-placeholder>
+
+ <!-- a bean that uses a blueprint property placeholder -->
+ <bean id="myCoolBean" class="org.apache.camel.test.blueprint.MyCoolBean">
+ <property name="say" value="${my.greeting}"/>
+ </bean>
+
+ <camelContext messageHistory="{{my.context.messageHistory}}" xmlns="http://camel.apache.org/schema/blueprint">
+
+ <route>
+ <from uri="direct:start"/>
+ <bean ref="myCoolBean" method="saySomething"/>
+ <to uri="mock:result"/>
+ </route>
+
+ </camelContext>
+
+</blueprint>