CAMEL-10393: camel-properties: Add an option to disable using default value if a property does not exists
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 @@
| 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).
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 @@
* @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 @@
* 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;
}
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 @@
@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 @@
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 @@
// 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);
}
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 @@
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 @@
uri, prop,
prefixToken, suffixToken,
propertyPrefixResolved, propertySuffixResolved,
- fallbackToUnaugmentedProperty, disableDefaultValueResolution);
+ fallbackToUnaugmentedProperty, defaultFallbackEnabled);
} else {
return propertiesParser.parseUri(uri, prop, prefixToken, suffixToken);
}
@@ -344,15 +344,15 @@
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() {
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 @@
props.put("p:message", "my message");
PropertiesComponent component = new PropertiesComponent();
- component.setDisableDefaultValueResolution(true);
+ component.setDefaultFallbackEnabled(false);
component.setInitialProperties(props);
context.addComponent("properties", component);
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 @@
* 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 @@
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() {
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 @@
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());
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 @@
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 @@
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() {
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 @@
@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);
}
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"/>