This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-13947 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 61d5f5eb570cc7851c5a5db6cf1e8f306bea0276 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Sep 25 18:12:11 2019 +0200 CAMEL-13947: PropertiesComponent should be a static service and resolved like other similar features. --- core/camel-base/src/main/docs/simple-language.adoc | 13 ----- .../core/xml/AbstractCamelContextFactoryBean.java | 2 +- .../simple/SimplePropertiesNestedTest.java | 60 ---------------------- .../language/simple/SimpleWithPropertiesTest.java | 50 ------------------ ...RoutesWithPropertyPlaceholdersFromXmlPTest.java | 7 +-- .../management/ManagedFromRestPlaceholderTest.java | 7 +-- .../ManagedRouteDumpRouteAsXmlPlaceholderTest.java | 7 +-- 7 files changed, 4 insertions(+), 142 deletions(-) diff --git a/core/camel-base/src/main/docs/simple-language.adoc b/core/camel-base/src/main/docs/simple-language.adoc index 0c6e3c0..5fc83b4 100644 --- a/core/camel-base/src/main/docs/simple-language.adoc +++ b/core/camel-base/src/main/docs/simple-language.adoc @@ -179,10 +179,6 @@ Specifying a method name you must use dot as separator. We also support the ?method=methodname syntax that is used by the xref:components::bean-component.adoc[Bean] component. -|`properties:key:default` |String |Lookup a property with the given key. If the key does -not exists or has no value, then an optional default value can be -specified. - |routeId |String |Returns the id of the current route the Exchange is being routed. @@ -779,15 +775,6 @@ a `java.util.Map` and we then lookup with the key `gold` and return the value. If the header is not convertible to Map an exception is thrown. If the header with name `type` does not exist `null` is returned. -You can nest functions, such as shown below: - -[source,xml] ----- -<setHeader name="myHeader"> - <simple>${properties:${header.someKey}}</simple> -</setHeader> ----- - == Referring to constants or enums Suppose you have an enum for customers diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java index 8fbc61d..04ea832 100644 --- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java +++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java @@ -654,7 +654,7 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex } // register the properties component - getContext().addComponent("properties", pc); + getContext().setPropertiesComponent(pc); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimplePropertiesNestedTest.java b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimplePropertiesNestedTest.java deleted file mode 100644 index aeb9cb8..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimplePropertiesNestedTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.language.simple; - -import org.apache.camel.CamelContext; -import org.apache.camel.ContextTestSupport; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.properties.PropertiesComponent; -import org.junit.Test; - -/** - * - */ -public class SimplePropertiesNestedTest extends ContextTestSupport { - - @Test - public void testSimplePropertiesNested() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - mock.expectedBodiesReceived("Hello World"); - mock.expectedHeaderReceived("myHeader", "Beer taste good"); - - template.sendBodyAndHeader("direct:start", "Hello World", "beer", "bar.quote"); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").setHeader("myHeader").simple("${properties:${header.beer}}").to("mock:result"); - } - }; - } - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - context.getPropertiesComponent().setLocation("org/apache/camel/component/properties/bar.properties"); - return context; - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWithPropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWithPropertiesTest.java deleted file mode 100644 index 262df63..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWithPropertiesTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.language.simple; - -import org.apache.camel.CamelContext; -import org.apache.camel.Exchange; -import org.apache.camel.builder.SimpleBuilder; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.support.DefaultExchange; -import org.junit.Assert; -import org.junit.Test; - -/** - * - */ -public class SimpleWithPropertiesTest { - - /** - * A property from the property component in a expression is processed when - * the expression is evaluated with exchange See - * https://issues.apache.org/jira/browse/CAMEL-4843 Now camel doesn't - * support the properties expression of {{test}} - */ - @Test - public void testProperty() throws Exception { - System.setProperty("test", "testValue"); - CamelContext context = new DefaultCamelContext(); - - // try to setup the property - Exchange exchange = new DefaultExchange(context); - String result = SimpleBuilder.simple("${properties:test}").evaluate(exchange, String.class); - Assert.assertEquals("testValue", result); - System.clearProperty("test"); - } - -} diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesWithPropertyPlaceholdersFromXmlPTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesWithPropertyPlaceholdersFromXmlPTest.java index 033c983..5606ae0 100644 --- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesWithPropertyPlaceholdersFromXmlPTest.java +++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesWithPropertyPlaceholdersFromXmlPTest.java @@ -25,7 +25,6 @@ import javax.management.ObjectName; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.properties.PropertiesComponent; import org.junit.Test; public class ManagedCamelContextUpdateRoutesWithPropertyPlaceholdersFromXmlPTest extends ManagementTestSupport { @@ -39,11 +38,7 @@ public class ManagedCamelContextUpdateRoutesWithPropertyPlaceholdersFromXmlPTest props.put("theBar", "mock:bar"); CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setLocations(new String[0]); - pc.setOverrideProperties(props); - + context.getPropertiesComponent().setOverrideProperties(props); return context; } diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedFromRestPlaceholderTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedFromRestPlaceholderTest.java index 656ce05..f20ba80 100644 --- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedFromRestPlaceholderTest.java +++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedFromRestPlaceholderTest.java @@ -23,7 +23,6 @@ import javax.management.ObjectName; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.component.rest.DummyRestConsumerFactory; import org.apache.camel.model.rest.CollectionFormat; import org.apache.camel.model.rest.RestParamType; @@ -35,11 +34,7 @@ public class ManagedFromRestPlaceholderTest extends ManagementTestSupport { protected CamelContext createCamelContext() throws Exception { CamelContext answer = super.createCamelContext(); answer.getRegistry().bind("dummy-test", new DummyRestConsumerFactory()); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/management/rest.properties"); - answer.addComponent("properties", pc); - + answer.getPropertiesComponent().setLocation("classpath:org/apache/camel/management/rest.properties"); return answer; } diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlPlaceholderTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlPlaceholderTest.java index 6db70f4..1767837 100644 --- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlPlaceholderTest.java +++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlPlaceholderTest.java @@ -24,7 +24,6 @@ import javax.management.ObjectName; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.properties.PropertiesComponent; import org.junit.Test; public class ManagedRouteDumpRouteAsXmlPlaceholderTest extends ManagementTestSupport { @@ -32,11 +31,7 @@ public class ManagedRouteDumpRouteAsXmlPlaceholderTest extends ManagementTestSup @Override protected CamelContext createCamelContext() throws Exception { CamelContext answer = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/management/rest.properties"); - answer.addComponent("properties", pc); - + answer.getPropertiesComponent().setLocation("classpath:org/apache/camel/management/rest.properties"); return answer; }
