Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5DB1910A16 for ; Wed, 4 Sep 2013 12:48:18 +0000 (UTC) Received: (qmail 47327 invoked by uid 500); 4 Sep 2013 12:48:18 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 47188 invoked by uid 500); 4 Sep 2013 12:48:18 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 47173 invoked by uid 99); 4 Sep 2013 12:48:16 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Sep 2013 12:48:16 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4ECF19000E3; Wed, 4 Sep 2013 12:48:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Wed, 04 Sep 2013 12:48:17 -0000 Message-Id: In-Reply-To: <6e08686c561d40aea87d9ccc83e20a5c@git.apache.org> References: <6e08686c561d40aea87d9ccc83e20a5c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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. 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 Authored: Wed Sep 4 14:47:39 2013 +0200 Committer: Claus Ibsen 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + file:{{my.resources.config.folder}}/etc/{{my.resources.config.file}} + + + + + + + + + + + + + + + + + +