CAMEL-10393: camel-properties: Add an option to disable using default value if a property does not exists
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0c17cda3 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0c17cda3 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0c17cda3 Branch: refs/heads/release/2.18.5 Commit: 0c17cda3ee2333e5f2c028e7e42a83f32162c007 Parents: 97d5eb1 Author: lburgazzoli <lburgazz...@gmail.com> Authored: Thu Oct 20 01:02:30 2016 +0200 Committer: Gregor Zurowski <gre...@zurowski.org> Committed: Mon Sep 18 21:00:10 2017 +0100 ---------------------------------------------------------------------- camel-core/src/main/docs/properties-component.adoc | 2 +- .../AugmentedPropertyNameAwarePropertiesParser.java | 8 ++++---- .../component/properties/DefaultPropertiesParser.java | 12 ++++++------ .../component/properties/PropertiesComponent.java | 12 ++++++------ .../PropertiesComponentDisableDefaultsTest.java | 2 +- .../springboot/PropertiesComponentConfiguration.java | 11 +++++------ .../core/xml/AbstractCamelContextFactoryBean.java | 4 ++-- .../core/xml/CamelPropertyPlaceholderDefinition.java | 14 +++++++------- .../spi/BridgePropertyPlaceholderConfigurer.java | 4 ++-- .../apache/camel/test/blueprint/default-values.xml | 2 +- 10 files changed, 35 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/camel-core/src/main/docs/properties-component.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/properties-component.adoc b/camel-core/src/main/docs/properties-component.adoc index b55849b..14291ca 100644 --- a/camel-core/src/main/docs/properties-component.adoc +++ b/camel-core/src/main/docs/properties-component.adoc @@ -37,7 +37,7 @@ The Properties component supports 16 options which are listed below. | propertyPrefix | String | Optional prefix prepended to property names before resolution. | propertySuffix | String | Optional suffix appended to property names before resolution. | fallbackToUnaugmentedProperty | boolean | 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. -| disableDefaultValueResolution | boolean | If true the component does not attempt to find a default for the key by looking after the colon separator. +| defaultFallbackEnabled | boolean | If true the component does not attempt to find a default for the key by looking after the colon separator. | ignoreMissingLocation | boolean | Whether to silently ignore if a location cannot be located such as a properties file not found. | prefixToken | String | Sets the value of the prefix token used to identify properties to replace. Setting a value of null restores the default token (link link DEFAULT_PREFIX_TOKEN). | suffixToken | String | Sets the value of the suffix token used to identify properties to replace. Setting a value of null restores the default token (link link DEFAULT_SUFFIX_TOKEN). http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/camel-core/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java b/camel-core/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java index dfe8df7..a244227 100644 --- a/camel-core/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java +++ b/camel-core/src/main/java/org/apache/camel/component/properties/AugmentedPropertyNameAwarePropertiesParser.java @@ -40,9 +40,9 @@ public interface AugmentedPropertyNameAwarePropertiesParser extends PropertiesPa * @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 disableDefaultValueResolution flag indicating if the value after colon - * should be the default value to use it - * the property has not been resolved + * @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 * @@ -50,5 +50,5 @@ public interface AugmentedPropertyNameAwarePropertiesParser extends PropertiesPa * is not found */ String parseUri(String text, Properties properties, String prefixToken, String suffixToken, - String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean disableDefaultValueResolution) throws IllegalArgumentException; + String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException; } http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/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 0bfef5b..f5f42d8 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 @@ -57,8 +57,8 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper @Override public String parseUri(String text, Properties properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, - boolean fallbackToUnaugmentedProperty, boolean disableDefaultValueResolution) throws IllegalArgumentException { - ParsingContext context = new ParsingContext(properties, prefixToken, suffixToken, propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, disableDefaultValueResolution); + boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException { + ParsingContext context = new ParsingContext(properties, prefixToken, suffixToken, propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); return context.parse(text); } @@ -76,17 +76,17 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper private final String propertyPrefix; private final String propertySuffix; private final boolean fallbackToUnaugmentedProperty; - private final boolean disableDefaultValueResolution; + private final boolean defaultFallbackEnabled; ParsingContext(Properties properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, - boolean fallbackToUnaugmentedProperty, boolean disableDefaultValueResolution) { + boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) { this.properties = properties; this.prefixToken = prefixToken; this.suffixToken = suffixToken; this.propertyPrefix = propertyPrefix; this.propertySuffix = propertySuffix; this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; - this.disableDefaultValueResolution = disableDefaultValueResolution; + this.defaultFallbackEnabled = defaultFallbackEnabled; } /** @@ -237,7 +237,7 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper // they key may have a get or else expression String defaultValue = null; - if (!disableDefaultValueResolution && key.contains(GET_OR_ELSE_TOKEN)) { + if (defaultFallbackEnabled && key.contains(GET_OR_ELSE_TOKEN)) { defaultValue = ObjectHelper.after(key, GET_OR_ELSE_TOKEN); key = ObjectHelper.before(key, GET_OR_ELSE_TOKEN); } http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/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 7bbdefa..8cd5ba9 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 @@ -100,7 +100,7 @@ public class PropertiesComponent extends UriEndpointComponent { private String propertySuffix; private String propertySuffixResolved; private boolean fallbackToUnaugmentedProperty = true; - private boolean disableDefaultValueResolution; + private boolean defaultFallbackEnabled = true; private String prefixToken = DEFAULT_PREFIX_TOKEN; private String suffixToken = DEFAULT_SUFFIX_TOKEN; private Properties initialProperties; @@ -211,7 +211,7 @@ public class PropertiesComponent extends UriEndpointComponent { uri, prop, prefixToken, suffixToken, propertyPrefixResolved, propertySuffixResolved, - fallbackToUnaugmentedProperty, disableDefaultValueResolution); + fallbackToUnaugmentedProperty, defaultFallbackEnabled); } else { return propertiesParser.parseUri(uri, prop, prefixToken, suffixToken); } @@ -344,15 +344,15 @@ public class PropertiesComponent extends UriEndpointComponent { this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; } - public boolean isDisableDefaultValueResolution() { - return disableDefaultValueResolution; + public boolean isDefaultFallbackEnabled() { + return defaultFallbackEnabled; } /** * If true, the component does not attempt to find a default for the key by looking after the colon separator. */ - public void setDisableDefaultValueResolution(boolean disableDefaultValueResolution) { - this.disableDefaultValueResolution = disableDefaultValueResolution; + public void setDefaultFallbackEnabled(boolean defaultFallbackEnabled) { + this.defaultFallbackEnabled = defaultFallbackEnabled; } public boolean isIgnoreMissingLocation() { http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java index 2f3af4b..8cc8d33 100644 --- a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java @@ -59,7 +59,7 @@ public class PropertiesComponentDisableDefaultsTest extends ContextTestSupport { props.put("p:message", "my message"); PropertiesComponent component = new PropertiesComponent(); - component.setDisableDefaultValueResolution(true); + component.setDefaultFallbackEnabled(false); component.setInitialProperties(props); context.addComponent("properties", component); http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java b/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java index 55b5f3a..cba77d5 100644 --- a/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java +++ b/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java @@ -82,7 +82,7 @@ public class PropertiesComponentConfiguration { * If true the component does not attempt to find a default for the key by * looking after the colon separator. */ - private Boolean disableDefaultValueResolution; + private Boolean defaultFallbackEnabled; /** * Whether to silently ignore if a location cannot be located such as a * properties file not found. @@ -188,13 +188,12 @@ public class PropertiesComponentConfiguration { this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; } - public Boolean getDisableDefaultValueResolution() { - return disableDefaultValueResolution; + public Boolean getDefaultFallbackEnabled() { + return defaultFallbackEnabled; } - public void setDisableDefaultValueResolution( - Boolean disableDefaultValueResolution) { - this.disableDefaultValueResolution = disableDefaultValueResolution; + public void setDefaultFallbackEnabled(Boolean defaultFallbackEnabled) { + this.defaultFallbackEnabled = defaultFallbackEnabled; } public Boolean getIgnoreMissingLocation() { http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/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 a195ee1..d26449b 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 @@ -599,8 +599,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex if (def.isFallbackToUnaugmentedProperty() != null) { pc.setFallbackToUnaugmentedProperty(def.isFallbackToUnaugmentedProperty()); } - if (def.getDisableDefaultValueResolution() != null) { - pc.setDisableDefaultValueResolution(def.getDisableDefaultValueResolution()); + if (def.getDefaultFallbackEnabled() != null) { + pc.setDefaultFallbackEnabled(def.getDefaultFallbackEnabled()); } pc.setPrefixToken(def.getPrefixToken()); http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/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 7ea2cee..6e3d638 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 @@ -54,8 +54,8 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { private String propertySuffix; @XmlAttribute @Metadata(defaultValue = "true") private Boolean fallbackToUnaugmentedProperty; - @XmlAttribute @Metadata(defaultValue = "false") - private Boolean disableDefaultValueResolution; + @XmlAttribute @Metadata(defaultValue = "true") + private Boolean defaultFallbackEnabled; @XmlAttribute @Metadata(defaultValue = "{{") private String prefixToken; @XmlAttribute @Metadata(defaultValue = "}}") @@ -156,15 +156,15 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; } - public Boolean getDisableDefaultValueResolution() { - return disableDefaultValueResolution; + public Boolean getDefaultFallbackEnabled() { + return defaultFallbackEnabled; } /** - * If true, the component does not attempt to find a default for the key by looking after the colon separator. + * If false, the component does not attempt to find a default for the key by looking after the colon separator. */ - public void setDisableDefaultValueResolution(Boolean disableDefaultValueResolution) { - this.disableDefaultValueResolution = disableDefaultValueResolution; + public void setDefaultFallbackEnabled(Boolean defaultFallbackEnabled) { + this.defaultFallbackEnabled = defaultFallbackEnabled; } public Boolean isIgnoreMissingLocation() { http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java ---------------------------------------------------------------------- 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 c085fad..bf9baa7 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 @@ -154,13 +154,13 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf @Override public String parseUri(String text, Properties properties, String prefixToken, String suffixToken, - String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean disableDefaultValueResolution) throws IllegalArgumentException { + String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) 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, disableDefaultValueResolution); + propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); } else { answer = parser.parseUri(text, properties, prefixToken, suffixToken); } http://git-wip-us.apache.org/repos/asf/camel/blob/0c17cda3/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/default-values.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/default-values.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/default-values.xml index 0fd2284..220c875 100644 --- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/default-values.xml +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/default-values.xml @@ -31,7 +31,7 @@ </cm:property-placeholder> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> - <propertyPlaceholder id="default-values-camel" location="blueprint:default-values" disableDefaultValueResolution="true"/> + <propertyPlaceholder id="default-values-camel" location="blueprint:default-values" defaultFallbackEnabled="false"/> <route> <from uri="direct:start"/>