This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch properties in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4451c7fd06006505bd445534c8d213caa96d448d Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Jul 3 07:12:03 2019 +0200 CAMEL-13720: Properties component - Remove complexity of augemented properties parser --- .../src/main/docs/properties-component.adoc | 5 +- ...AugmentedPropertyNameAwarePropertiesParser.java | 52 ------ .../properties/DefaultPropertiesParser.java | 59 +------ .../component/properties/PropertiesComponent.java | 65 +------- .../component/properties/PropertiesParser.java | 3 +- .../spi/BridgePropertyPlaceholderConfigurer.java | 58 +------ .../core/xml/AbstractCamelContextFactoryBean.java | 6 - .../xml/CamelPropertyPlaceholderDefinition.java | 40 ----- .../properties/PropertiesComponentTest.java | 182 --------------------- .../PropertiesComponentConfiguration.java | 39 ----- 10 files changed, 18 insertions(+), 491 deletions(-) diff --git a/components/camel-properties/src/main/docs/properties-component.adoc b/components/camel-properties/src/main/docs/properties-component.adoc index aa73ceb..65146ca 100644 --- a/components/camel-properties/src/main/docs/properties-component.adoc +++ b/components/camel-properties/src/main/docs/properties-component.adoc @@ -15,7 +15,7 @@ Where *key* is the key for the property to lookup === Options // component options: START -The Properties component supports 19 options, which are listed below. +The Properties component supports 16 options, which are listed below. @@ -28,9 +28,6 @@ The Properties component supports 19 options, which are listed below. | *propertiesResolver* (common) | To use a custom PropertiesResolver | | PropertiesResolver | *propertiesParser* (common) | To use a custom PropertiesParser | | PropertiesParser | *cache* (common) | Whether or not to cache loaded properties. The default value is true. | true | boolean -| *propertyPrefix* (advanced) | Optional prefix prepended to property names before resolution. | | String -| *propertySuffix* (advanced) | Optional suffix appended to property names before resolution. | | String -| *fallbackToUnaugmented Property* (advanced) | If true, first attempt resolution of property name augmented with propertyPrefix and propertySuffix before falling back the plain property name specified. If false, only the augmented property name is searched. | true | boolean | *defaultFallbackEnabled* (common) | If false, the component does not attempt to find a default for the key by looking after the colon separator. | true | boolean | *ignoreMissingLocation* (common) | Whether to silently ignore if a location cannot be located, such as a properties file not found. | false | boolean | *prefixToken* (advanced) | Sets the value of the prefix token used to identify properties to replace. Setting a value of null restores the default token (link DEFAULT_PREFIX_TOKEN). | {{ | String diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java deleted file mode 100644 index adc88803..0000000 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java +++ /dev/null @@ -1,52 +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.component.properties; - -/** - * Interface for property parses that can attempt parsing property names using a fixed property name prefix and suffix. - */ -public interface AugmentedPropertyNameAwarePropertiesParser extends PropertiesParser { - - /** - * Parses the string, applying the optional {@code propertyPrefix} and - * {@code propertySuffix} to the parsed property names, and replaces the - * property placeholders with values from the given properties. - * - * @param text the text to be parsed - * @param properties the properties resolved which values should be looked - * up - * @param prefixToken the prefix token - * @param suffixToken the suffix token - * @param propertyPrefix the optional property name prefix to augment parsed - * property names with - * @param propertySuffix the optional property name suffix to augment parsed - * property names with - * @param fallbackToUnaugmentedProperty flag indicating if the originally - * parsed property name should by used for resolution if there is - * no match to the augmented property name - * @param defaultFallbackEnabled flag indicating if the value after colon - * should be the default value to use it - * the property has not been resolved - * - * @return the parsed text with replaced placeholders - * - * @throws IllegalArgumentException if uri syntax is not valid or a property - * is not found - */ - String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, - String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException; -} diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java index 9c01340..659ebac 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java @@ -17,7 +17,6 @@ package org.apache.camel.component.properties; import java.util.HashSet; -import java.util.Properties; import java.util.Set; import org.apache.camel.util.ObjectHelper; @@ -30,7 +29,7 @@ import static org.apache.camel.util.IOHelper.lookupEnvironmentVariable; /** * A parser to parse a string which contains property placeholders. */ -public class DefaultPropertiesParser implements AugmentedPropertyNameAwarePropertiesParser { +public class DefaultPropertiesParser implements PropertiesParser { private static final String GET_OR_ELSE_TOKEN = ":"; protected final Logger log = LoggerFactory.getLogger(getClass()); @@ -53,15 +52,8 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper } @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken) throws IllegalArgumentException { - return parseUri(text, properties, prefixToken, suffixToken, null, null, false, false); - } - - @Override - public String parseUri(String text, PropertiesLookup properties, - String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, - boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException { - ParsingContext context = new ParsingContext(properties, prefixToken, suffixToken, propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); + public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, boolean defaultFallbackEnabled) throws IllegalArgumentException { + ParsingContext context = new ParsingContext(properties, prefixToken, suffixToken, defaultFallbackEnabled); return context.parse(text); } @@ -76,19 +68,12 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper private final PropertiesLookup properties; private final String prefixToken; private final String suffixToken; - private final String propertyPrefix; - private final String propertySuffix; - private final boolean fallbackToUnaugmentedProperty; private final boolean defaultFallbackEnabled; - ParsingContext(PropertiesLookup properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, - boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) { + ParsingContext(PropertiesLookup properties, String prefixToken, String suffixToken, boolean defaultFallbackEnabled) { this.properties = properties; this.prefixToken = prefixToken; this.suffixToken = suffixToken; - this.propertyPrefix = propertyPrefix; - this.propertySuffix = propertySuffix; - this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; this.defaultFallbackEnabled = defaultFallbackEnabled; } @@ -245,17 +230,9 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper key = StringHelper.before(key, GET_OR_ELSE_TOKEN); } - String augmentedKey = getAugmentedKey(key); - boolean shouldFallback = fallbackToUnaugmentedProperty && !key.equals(augmentedKey); - - String value = doGetPropertyValue(augmentedKey); - if (value == null && shouldFallback) { - log.debug("Property with key [{}] not found, attempting with unaugmented key: {}", augmentedKey, key); - value = doGetPropertyValue(key); - } - + String value = doGetPropertyValue(key); if (value == null && defaultValue != null) { - log.debug("Property with key [{}] not found, using default value: {}", augmentedKey, defaultValue); + log.debug("Property with key [{}] not found, using default value: {}", key, defaultValue); value = defaultValue; } @@ -265,10 +242,7 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper // 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("]) "); - } + esb.append("Property with key [").append(key).append("] "); esb.append("not found in properties from text: ").append(input); throw new IllegalArgumentException(esb.toString()); } @@ -277,25 +251,6 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper } /** - * Gets the augmented key of the given base key - * - * @param key Base key - * @return Augmented key - */ - private String getAugmentedKey(String key) { - String augmentedKey = key; - if (propertyPrefix != null) { - log.debug("Augmenting property key [{}] with prefix: {}", key, propertyPrefix); - augmentedKey = propertyPrefix + augmentedKey; - } - if (propertySuffix != null) { - log.debug("Augmenting property key [{}] with suffix: {}", key, propertySuffix); - augmentedKey = augmentedKey + propertySuffix; - } - return augmentedKey; - } - - /** * Gets the property with the given key, it returns {@code null} if the property is not found * * @param key Key of the property diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java index 861271a..68b6453 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java @@ -116,13 +116,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. private String encoding; @Metadata(defaultValue = "true") private boolean cache = true; - @Metadata(label = "advanced") - private String propertyPrefix; - @Metadata(label = "advanced") - private String propertySuffix; - private transient String propertySuffixResolved; - @Metadata(label = "advanced", defaultValue = "true") - private boolean fallbackToUnaugmentedProperty = true; @Metadata(defaultValue = "true") private boolean defaultFallbackEnabled = true; @Metadata(label = "advanced", defaultValue = DEFAULT_PREFIX_TOKEN) @@ -275,22 +268,8 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. } log.trace("Parsing uri {} with properties: {}", uri, prop); - PropertiesLookup properties = new DefaultPropertiesLookup(prop); - - if (propertiesParser instanceof AugmentedPropertyNameAwarePropertiesParser) { - return ((AugmentedPropertyNameAwarePropertiesParser) propertiesParser).parseUri( - uri, - properties, - prefixToken, - suffixToken, - propertyPrefixResolved, - propertySuffixResolved, - fallbackToUnaugmentedProperty, - defaultFallbackEnabled); - } else { - return propertiesParser.parseUri(uri, properties, prefixToken, suffixToken); - } + return propertiesParser.parseUri(uri, properties, prefixToken, suffixToken, defaultFallbackEnabled); } public List<PropertiesLocation> getLocations() { @@ -408,48 +387,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. this.cache = cache; } - public String getPropertyPrefix() { - return propertyPrefix; - } - - /** - * Optional prefix prepended to property names before resolution. - */ - public void setPropertyPrefix(String propertyPrefix) { - this.propertyPrefix = propertyPrefix; - this.propertyPrefixResolved = propertyPrefix; - if (ObjectHelper.isNotEmpty(this.propertyPrefix)) { - this.propertyPrefixResolved = FilePathResolver.resolvePath(this.propertyPrefix); - } - } - - public String getPropertySuffix() { - return propertySuffix; - } - - /** - * Optional suffix appended to property names before resolution. - */ - public void setPropertySuffix(String propertySuffix) { - this.propertySuffix = propertySuffix; - this.propertySuffixResolved = propertySuffix; - if (ObjectHelper.isNotEmpty(this.propertySuffix)) { - this.propertySuffixResolved = FilePathResolver.resolvePath(this.propertySuffix); - } - } - - public boolean isFallbackToUnaugmentedProperty() { - return fallbackToUnaugmentedProperty; - } - - /** - * If true, first attempt resolution of property name augmented with propertyPrefix and propertySuffix - * before falling back the plain property name specified. If false, only the augmented property name is searched. - */ - public void setFallbackToUnaugmentedProperty(boolean fallbackToUnaugmentedProperty) { - this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; - } - @ManagedAttribute(description = "Whether to support using fallback values if a property cannot be found") public boolean isDefaultFallbackEnabled() { return defaultFallbackEnabled; diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesParser.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesParser.java index 992cb43..34634f8 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesParser.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesParser.java @@ -28,10 +28,11 @@ public interface PropertiesParser { * @param properties the properties resolved which values should be looked up * @param prefixToken the prefix token * @param suffixToken the suffix token + * @param fallback whether to support using fallback values if a property cannot be found * @return the parsed text with replaced placeholders * @throws IllegalArgumentException if uri syntax is not valid or a property is not found */ - String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken) throws IllegalArgumentException; + String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, boolean fallback) throws IllegalArgumentException; /** * While parsing the uri using {@link #parseUri(String, PropertiesLookup, String, String) parseUri} each diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java index e4d5666..4257147 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Properties; import org.apache.camel.CamelContext; -import org.apache.camel.component.properties.AugmentedPropertyNameAwarePropertiesParser; import org.apache.camel.component.properties.DefaultPropertiesLookup; import org.apache.camel.component.properties.PropertiesLocation; import org.apache.camel.component.properties.PropertiesLookup; @@ -37,7 +36,7 @@ import org.springframework.util.PropertyPlaceholderHelper; * A {@link PropertyPlaceholderConfigurer} that bridges Camel's <a href="http://camel.apache.org/using-propertyplaceholder.html"> * property placeholder</a> with the Spring property placeholder mechanism. */ -public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements PropertiesResolver, AugmentedPropertyNameAwarePropertiesParser { +public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements PropertiesResolver, PropertiesParser { // NOTE: this class must be in the spi package as if its in the root package, then Spring fails to parse the XML // files due some weird spring issue. But that is okay as having this class in the spi package is fine anyway. @@ -157,17 +156,9 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, - String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException { - + public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, boolean fallback) throws IllegalArgumentException { // first let Camel parse the text as it may contain Camel placeholders - String answer; - if (parser instanceof AugmentedPropertyNameAwarePropertiesParser) { - answer = ((AugmentedPropertyNameAwarePropertiesParser) parser).parseUri(text, properties, prefixToken, suffixToken, - propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); - } else { - answer = parser.parseUri(text, properties, prefixToken, suffixToken); - } + String answer = parser.parseUri(text, properties, prefixToken, suffixToken, false); // then let Spring parse it to resolve any Spring placeholders if (answer != null) { @@ -179,17 +170,6 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken) throws IllegalArgumentException { - String answer = parser.parseUri(text, properties, prefixToken, suffixToken); - if (answer != null) { - answer = springResolvePlaceholders(answer, properties); - } else { - answer = springResolvePlaceholders(text, properties); - } - return answer; - } - - @Override public String parseProperty(String key, String value, PropertiesLookup properties) { String answer = parser.parseProperty(key, value, properties); if (answer != null) { @@ -247,7 +227,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } } - private final class BridgePropertiesParser implements PropertiesParser, AugmentedPropertyNameAwarePropertiesParser { + private final class BridgePropertiesParser implements PropertiesParser { private final PropertiesParser delegate; private final PropertiesParser parser; @@ -258,39 +238,15 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, - boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException { - String answer = null; - if (delegate != null) { - if (delegate instanceof AugmentedPropertyNameAwarePropertiesParser) { - answer = ((AugmentedPropertyNameAwarePropertiesParser)this.delegate).parseUri(text, properties, - prefixToken, suffixToken, propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); - } else { - answer = delegate.parseUri(text, properties, prefixToken, suffixToken); - } - } - if (answer != null) { - text = answer; - } - if (parser instanceof AugmentedPropertyNameAwarePropertiesParser) { - answer = ((AugmentedPropertyNameAwarePropertiesParser)this.parser).parseUri(text, properties, - prefixToken, suffixToken, propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); - } else { - answer = parser.parseUri(text, properties, prefixToken, suffixToken); - } - return answer; - } - - @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken) throws IllegalArgumentException { + public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, boolean fallback) throws IllegalArgumentException { String answer = null; if (delegate != null) { - answer = delegate.parseUri(text, properties, prefixToken, suffixToken); + answer = delegate.parseUri(text, properties, prefixToken, suffixToken, fallback); } if (answer != null) { text = answer; } - return parser.parseUri(text, properties, prefixToken, suffixToken); + return parser.parseUri(text, properties, prefixToken, suffixToken, fallback); } @Override 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 50b0adc..359ba9a 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 @@ -656,12 +656,6 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex pc.setPropertiesParser(parser); } - pc.setPropertyPrefix(def.getPropertyPrefix()); - pc.setPropertySuffix(def.getPropertySuffix()); - - if (def.isFallbackToUnaugmentedProperty() != null) { - pc.setFallbackToUnaugmentedProperty(def.isFallbackToUnaugmentedProperty()); - } if (def.getDefaultFallbackEnabled() != null) { pc.setDefaultFallbackEnabled(def.getDefaultFallbackEnabled()); } diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java index e356a0a..c9772fa 100644 --- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java +++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java @@ -46,12 +46,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { private String propertiesResolverRef; @XmlAttribute private String propertiesParserRef; - @XmlAttribute - private String propertyPrefix; - @XmlAttribute - private String propertySuffix; - @XmlAttribute @Metadata(defaultValue = "true") - private Boolean fallbackToUnaugmentedProperty; @XmlAttribute @Metadata(defaultValue = "true") private Boolean defaultFallbackEnabled; @XmlAttribute @Metadata(defaultValue = "{{") @@ -122,40 +116,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { this.propertiesParserRef = propertiesParserRef; } - public String getPropertyPrefix() { - return propertyPrefix; - } - - /** - * Optional prefix prepended to property names before resolution. - */ - public void setPropertyPrefix(String propertyPrefix) { - this.propertyPrefix = propertyPrefix; - } - - public String getPropertySuffix() { - return propertySuffix; - } - - /** - * Optional suffix appended to property names before resolution. - */ - public void setPropertySuffix(String propertySuffix) { - this.propertySuffix = propertySuffix; - } - - public Boolean isFallbackToUnaugmentedProperty() { - return fallbackToUnaugmentedProperty; - } - - /** - * If true, first attempt resolution of property name augmented with propertyPrefix and propertySuffix - * before falling back the plain property name specified. If false, only the augmented property name is searched. - */ - public void setFallbackToUnaugmentedProperty(Boolean fallbackToUnaugmentedProperty) { - this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; - } - public Boolean getDefaultFallbackEnabled() { return defaultFallbackEnabled; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java index 7383265..8374138 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java @@ -280,188 +280,6 @@ public class PropertiesComponentTest extends ContextTestSupport { } @Test - public void testPropertiesComponentPropertyPrefix() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertyPrefix("cool."); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:end"); - from("direct:foo").to("properties:mock:{{result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2); - - template.sendBody("direct:start", "Hello World"); - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentParameterizedPropertyPrefix() throws Exception { - System.setProperty("myPrefix", "cool"); - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertyPrefix("${myPrefix}."); - pc.setPropertySuffix(".xx"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:end"); - from("direct:foo").to("properties:mock:{{result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2); - - template.sendBody("direct:start", "Hello World"); - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - - System.clearProperty("myPrefix"); - } - - @Test - public void testPropertiesComponentPropertyPrefixFallbackDefault() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertyPrefix("cool."); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool.end"); - from("direct:foo").to("properties:mock:{{result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2); - - template.sendBody("direct:start", "Hello World"); - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentPropertyPrefixFallbackDefaultNotFound() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertyPrefix("cool."); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:doesnotexist"); - } - }); - - try { - context.start(); - - fail("Should throw exception"); - } catch (Exception e) { - ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause()); - IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause()); - assertEquals("Property with key [cool.doesnotexist] (and original key [doesnotexist]) not found in properties from text: {{doesnotexist}}", iae.getMessage()); - } - } - - @Test - public void testPropertiesComponentPropertyPrefixFallbackFalse() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertyPrefix("cool."); - pc.setFallbackToUnaugmentedProperty(false); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool.end"); - from("direct:foo").to("properties:mock:{{result}}"); - } - }); - - try { - context.start(); - - fail("Should throw exception"); - } catch (Exception e) { - ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause()); - IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause()); - assertEquals("Property with key [cool.cool.end] not found in properties from text: {{cool.end}}", iae.getMessage()); - } - } - - @Test - public void testPropertiesComponentPropertySuffix() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertySuffix(".end"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(1); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentPropertySuffixFallbackDefault() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertySuffix(".end"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool.end"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(1); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentPropertySuffixFallbackFalse() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPropertySuffix(".end"); - pc.setFallbackToUnaugmentedProperty(false); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool.end"); - } - }); - - try { - context.start(); - - fail("Should throw exception"); - } catch (Exception e) { - ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause()); - IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause()); - assertEquals("Property with key [cool.end.end] not found in properties from text: {{cool.end}}", iae.getMessage()); - } - } - - @Test public void testJvmSystemPropertyNotFound() throws Exception { try { context.addRoutes(new RouteBuilder() { diff --git a/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java index fc703a4..3d81f6c 100644 --- a/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java @@ -72,20 +72,6 @@ public class PropertiesComponentConfiguration */ private Boolean cache = true; /** - * Optional prefix prepended to property names before resolution. - */ - private String propertyPrefix; - /** - * Optional suffix appended to property names before resolution. - */ - private String propertySuffix; - /** - * If true, first attempt resolution of property name augmented with - * propertyPrefix and propertySuffix before falling back the plain property - * name specified. If false, only the augmented property name is searched. - */ - private Boolean fallbackToUnaugmentedProperty = true; - /** * If false, the component does not attempt to find a default for the key by * looking after the colon separator. */ @@ -189,31 +175,6 @@ public class PropertiesComponentConfiguration this.cache = cache; } - public String getPropertyPrefix() { - return propertyPrefix; - } - - public void setPropertyPrefix(String propertyPrefix) { - this.propertyPrefix = propertyPrefix; - } - - public String getPropertySuffix() { - return propertySuffix; - } - - public void setPropertySuffix(String propertySuffix) { - this.propertySuffix = propertySuffix; - } - - public Boolean getFallbackToUnaugmentedProperty() { - return fallbackToUnaugmentedProperty; - } - - public void setFallbackToUnaugmentedProperty( - Boolean fallbackToUnaugmentedProperty) { - this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; - } - public Boolean getDefaultFallbackEnabled() { return defaultFallbackEnabled; }