This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-13760 in repository https://gitbox.apache.org/repos/asf/camel.git
commit b236efd25c2b2d628e8825435181641779d7721c Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Jul 18 11:17:29 2019 +0200 CAMEL-13760: camel3 - Remove configuring prefix and suffix token on property placeholder as it clashes and causes problems such as with simple language, and potentially elsewhere. --- MIGRATION.md | 3 ++ .../blueprint/handler/CamelNamespaceHandler.java | 8 ++-- .../src/main/docs/properties-component.adoc | 4 +- .../properties/DefaultPropertiesParser.java | 28 +++++------ .../component/properties/PropertiesComponent.java | 42 +++------------- .../component/properties/PropertiesParser.java | 7 +-- .../spi/BridgePropertyPlaceholderConfigurer.java | 10 ++-- .../properties/SpringPropertiesComponent2Test.java | 29 ----------- .../properties/SpringPropertiesComponent2Test.xml | 56 ---------------------- .../main/java/org/apache/camel/CamelContext.java | 2 + .../org/apache/camel/spi/PropertiesComponent.java | 14 +++--- .../camel/impl/engine/AbstractCamelContext.java | 6 ++- .../impl/engine/CamelPostProcessorHelper.java | 5 +- .../impl/engine/DefaultCamelBeanPostProcessor.java | 3 +- .../core/xml/AbstractCamelContextFactoryBean.java | 3 -- .../xml/CamelPropertyPlaceholderDefinition.java | 28 ----------- .../camel/model/ProcessorDefinitionHelper.java | 8 ++-- .../properties/PropertiesComponentTest.java | 30 ------------ .../apache/camel/support/IntrospectionSupport.java | 4 +- .../camel/support/builder/ExpressionBuilder.java | 2 +- .../PropertiesComponentConfiguration.java | 28 ----------- 21 files changed, 60 insertions(+), 260 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index ea8a343..16a16f6 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -90,8 +90,11 @@ The Camel `Main` class has been moved out of `camel-core` into `camel-main` so y ### Properties component +The `properties` component has configuring custom prefix and suffix tokens removed as if in use, they had potential issues with clashing with simple languages and elsewhere. The default tokens are now hardcoded and always in use. + The `properties` component has some advanced options removed: `propertyPrefix`, `propertySuffix`, and `fallbackToUnaugmented`; these options was never really useable for end users anyway. The option `propertiesResolver` has also been removed as you should use `PropertiesSource` instead. + ### Removed components We have removed all deprecated components from Camel 2.x, also including the old `camel-http` component. Instead you can use `camel-http4`. diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java index 568395a..84b52df 100644 --- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java @@ -688,7 +688,7 @@ public class CamelNamespaceHandler implements NamespaceHandler { private static ComponentMetadata getDataformatResolverReference(ParserContext context, String dataformat) { // we cannot resolve dataformat names using property placeholders at this point in time - if (dataformat.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { + if (dataformat.startsWith(PropertiesComponent.PREFIX_TOKEN)) { return null; } ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry(); @@ -722,7 +722,7 @@ public class CamelNamespaceHandler implements NamespaceHandler { private static ComponentMetadata getLanguageResolverReference(ParserContext context, String language) { // we cannot resolve language names using property placeholders at this point in time - if (language.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { + if (language.startsWith(PropertiesComponent.PREFIX_TOKEN)) { return null; } ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry(); @@ -756,7 +756,7 @@ public class CamelNamespaceHandler implements NamespaceHandler { private static ComponentMetadata getComponentResolverReference(ParserContext context, String component) { // we cannot resolve component names using property placeholders at this point in time - if (component.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { + if (component.startsWith(PropertiesComponent.PREFIX_TOKEN)) { return null; } ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry(); @@ -1187,7 +1187,7 @@ public class CamelNamespaceHandler implements NamespaceHandler { private void findUriComponent(String uri, Set<String> components) { // if the uri is a placeholder then skip it - if (uri == null || uri.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { + if (uri == null || uri.startsWith(PropertiesComponent.PREFIX_TOKEN)) { return; } diff --git a/components/camel-properties/src/main/docs/properties-component.adoc b/components/camel-properties/src/main/docs/properties-component.adoc index a47fb77..2da48fe 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 14 options, which are listed below. +The Properties component supports 12 options, which are listed below. @@ -28,8 +28,6 @@ The Properties component supports 14 options, which are listed below. | *propertiesParser* (common) | To use a custom PropertiesParser | | PropertiesParser | *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 -| *suffixToken* (advanced) | Sets the value of the suffix token used to identify properties to replace. Setting a value of null restores the default token (link DEFAULT_SUFFIX_TOKEN). | }} | String | *initialProperties* (advanced) | Sets initial properties which will be used before any locations are resolved. | | Properties | *overrideProperties* (advanced) | Sets a special list of override properties that take precedence and will use first, if a property exist. | | Properties | *systemPropertiesMode* (common) | Sets the system property mode. The default mode (override) is to use system properties if present, and override any existing properties. | 2 | int 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 66b5392..e6afa7f 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 @@ -24,6 +24,8 @@ import org.apache.camel.util.StringHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.camel.spi.PropertiesComponent.PREFIX_TOKEN; +import static org.apache.camel.spi.PropertiesComponent.SUFFIX_TOKEN; import static org.apache.camel.util.IOHelper.lookupEnvironmentVariable; /** @@ -52,8 +54,8 @@ public class DefaultPropertiesParser implements PropertiesParser { } @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, boolean defaultFallbackEnabled) throws IllegalArgumentException { - ParsingContext context = new ParsingContext(properties, prefixToken, suffixToken, defaultFallbackEnabled); + public String parseUri(String text, PropertiesLookup properties, boolean defaultFallbackEnabled) throws IllegalArgumentException { + ParsingContext context = new ParsingContext(properties, defaultFallbackEnabled); return context.parse(text); } @@ -66,14 +68,10 @@ public class DefaultPropertiesParser implements PropertiesParser { */ private final class ParsingContext { private final PropertiesLookup properties; - private final String prefixToken; - private final String suffixToken; private final boolean defaultFallbackEnabled; - ParsingContext(PropertiesLookup properties, String prefixToken, String suffixToken, boolean defaultFallbackEnabled) { + ParsingContext(PropertiesLookup properties, boolean defaultFallbackEnabled) { this.properties = properties; - this.prefixToken = prefixToken; - this.suffixToken = suffixToken; this.defaultFallbackEnabled = defaultFallbackEnabled; } @@ -129,7 +127,7 @@ public class DefaultPropertiesParser implements PropertiesParser { // If not found, ensure that there is no valid prefix token in the string if (suffix == -1) { if (getMatchingPrefixIndex(input, input.length()) != -1) { - throw new IllegalArgumentException(String.format("Missing %s from the text: %s", suffixToken, input)); + throw new IllegalArgumentException(String.format("Missing %s from the text: %s", SUFFIX_TOKEN, input)); } return null; } @@ -137,12 +135,12 @@ public class DefaultPropertiesParser implements PropertiesParser { // Find the index of the prefix token that matches the suffix token int prefix = getMatchingPrefixIndex(input, suffix); if (prefix == -1) { - throw new IllegalArgumentException(String.format("Missing %s from the text: %s", prefixToken, input)); + throw new IllegalArgumentException(String.format("Missing %s from the text: %s", PREFIX_TOKEN, input)); } - String key = input.substring(prefix + prefixToken.length(), suffix); + String key = input.substring(prefix + PREFIX_TOKEN.length(), suffix); String value = getPropertyValue(key, input); - return new Property(prefix, suffix + suffixToken.length(), key, value); + return new Property(prefix, suffix + SUFFIX_TOKEN.length(), key, value); } /** @@ -154,8 +152,8 @@ public class DefaultPropertiesParser implements PropertiesParser { private int getSuffixIndex(String input) { int index = -1; do { - index = input.indexOf(suffixToken, index + 1); - } while (index != -1 && isQuoted(input, index, suffixToken)); + index = input.indexOf(SUFFIX_TOKEN, index + 1); + } while (index != -1 && isQuoted(input, index, SUFFIX_TOKEN)); return index; } @@ -169,8 +167,8 @@ public class DefaultPropertiesParser implements PropertiesParser { private int getMatchingPrefixIndex(String input, int suffixIndex) { int index = suffixIndex; do { - index = input.lastIndexOf(prefixToken, index - 1); - } while (index != -1 && isQuoted(input, index, prefixToken)); + index = input.lastIndexOf(PREFIX_TOKEN, index - 1); + } while (index != -1 && isQuoted(input, index, PREFIX_TOKEN)); return index; } 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 25c4b25..37c0c69 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 @@ -114,10 +114,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. private String encoding; @Metadata(defaultValue = "true") private boolean defaultFallbackEnabled = true; - @Metadata(label = "advanced", defaultValue = DEFAULT_PREFIX_TOKEN) - private String prefixToken = DEFAULT_PREFIX_TOKEN; - @Metadata(label = "advanced", defaultValue = DEFAULT_SUFFIX_TOKEN) - private String suffixToken = DEFAULT_SUFFIX_TOKEN; @Metadata(label = "advanced") private Properties initialProperties; @Metadata(label = "advanced") @@ -208,15 +204,15 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. protected String parseUri(String uri, PropertiesLookup properties) { // enclose tokens if missing - if (!uri.contains(prefixToken) && !uri.startsWith(prefixToken)) { - uri = prefixToken + uri; + if (!uri.contains(PREFIX_TOKEN) && !uri.startsWith(PREFIX_TOKEN)) { + uri = PREFIX_TOKEN + uri; } - if (!uri.contains(suffixToken) && !uri.endsWith(suffixToken)) { - uri = uri + suffixToken; + if (!uri.contains(SUFFIX_TOKEN) && !uri.endsWith(SUFFIX_TOKEN)) { + uri = uri + SUFFIX_TOKEN; } log.trace("Parsing uri {}", uri); - return propertiesParser.parseUri(uri, properties, prefixToken, suffixToken, defaultFallbackEnabled); + return propertiesParser.parseUri(uri, properties, defaultFallbackEnabled); } @SuppressWarnings("unchecked") @@ -350,36 +346,12 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. @ManagedAttribute(description = "Prefix token") public String getPrefixToken() { - return prefixToken; - } - - /** - * Sets the value of the prefix token used to identify properties to replace. Setting a value of - * {@code null} restores the default token (@link {@link #DEFAULT_PREFIX_TOKEN}). - */ - public void setPrefixToken(String prefixToken) { - if (prefixToken == null) { - this.prefixToken = DEFAULT_PREFIX_TOKEN; - } else { - this.prefixToken = prefixToken; - } + return PREFIX_TOKEN; } @ManagedAttribute(description = "Suffix token") public String getSuffixToken() { - return suffixToken; - } - - /** - * Sets the value of the suffix token used to identify properties to replace. Setting a value of - * {@code null} restores the default token (@link {@link #DEFAULT_SUFFIX_TOKEN}). - */ - public void setSuffixToken(String suffixToken) { - if (suffixToken == null) { - this.suffixToken = DEFAULT_SUFFIX_TOKEN; - } else { - this.suffixToken = suffixToken; - } + return SUFFIX_TOKEN; } public Properties getInitialProperties() { 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 34634f8..78b89ec 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 @@ -26,17 +26,14 @@ public interface PropertiesParser { * * @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 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, boolean fallback) throws IllegalArgumentException; + String parseUri(String text, PropertiesLookup properties, boolean fallback) throws IllegalArgumentException; /** - * While parsing the uri using {@link #parseUri(String, PropertiesLookup, String, String) parseUri} each - * parsed property found invokes this callback. + * While parsing the uri using parseUri method each parsed property found invokes this callback. * <p/> * This strategy method allows you to hook into the parsing and do custom lookup and return the actual value to use. * 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 4f2229a..44739ea 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 @@ -79,9 +79,9 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, boolean fallback) throws IllegalArgumentException { + public String parseUri(String text, PropertiesLookup properties, boolean fallback) throws IllegalArgumentException { // first let Camel parse the text as it may contain Camel placeholders - String answer = parser.parseUri(text, properties, prefixToken, suffixToken, fallback); + String answer = parser.parseUri(text, properties, fallback); // then let Spring parse it to resolve any Spring placeholders if (answer != null) { @@ -167,15 +167,15 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, boolean fallback) throws IllegalArgumentException { + public String parseUri(String text, PropertiesLookup properties, boolean fallback) throws IllegalArgumentException { String answer = null; if (delegate != null) { - answer = delegate.parseUri(text, properties, prefixToken, suffixToken, fallback); + answer = delegate.parseUri(text, properties, fallback); } if (answer != null) { text = answer; } - return parser.parseUri(text, properties, prefixToken, suffixToken, fallback); + return parser.parseUri(text, properties, fallback); } @Override diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponent2Test.java b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponent2Test.java deleted file mode 100644 index 6b2abe5..0000000 --- a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringPropertiesComponent2Test.java +++ /dev/null @@ -1,29 +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; - -import org.springframework.context.support.AbstractXmlApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class SpringPropertiesComponent2Test extends BaseSpringPropertiesComponentTest { - - @Override - protected AbstractXmlApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/component/properties/SpringPropertiesComponent2Test.xml"); - } - -} \ No newline at end of file diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponent2Test.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponent2Test.xml deleted file mode 100644 index 5a277e1..0000000 --- a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringPropertiesComponent2Test.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - 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. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd - "> - - <camelContext xmlns="http://camel.apache.org/schema/spring"> - - <propertyPlaceholder id="properties" - location="classpath:org/apache/camel/component/properties/cheese.properties" - prefixToken="[[" - suffixToken="]]" - xmlns="http://camel.apache.org/schema/spring"/> - - <route> - <from uri="direct:start"/> - <to uri="properties:[[cool.end]]"/> - </route> - - <route> - <from uri="direct:bar"/> - <to uri="properties:mock:[[cool.bar]]"/> - </route> - - <route> - <from uri="direct:start2"/> - <to uri="[[cool.end]]"/> - </route> - - <route> - <from uri="direct:bar2"/> - <to uri="mock:[[cool.bar]]"/> - </route> - </camelContext> - -</beans> diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java index 3a41241..d2db232 100644 --- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java +++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java @@ -743,6 +743,7 @@ public interface CamelContext extends StatefulService, RuntimeConfiguration { * * @return the prefix token or {@code null} */ + @Deprecated String getPropertyPrefixToken(); /** @@ -751,6 +752,7 @@ public interface CamelContext extends StatefulService, RuntimeConfiguration { * * @return the suffix token or {@code null} */ + @Deprecated String getPropertySuffixToken(); /** diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java index 87fe784..247c6b1 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java @@ -30,14 +30,14 @@ import org.apache.camel.StaticService; public interface PropertiesComponent extends Component, StaticService { /** - * The default prefix token. + * The prefix token. */ - String DEFAULT_PREFIX_TOKEN = "{{"; + String PREFIX_TOKEN = "{{"; /** - * The default suffix token. + * The suffix token. */ - String DEFAULT_SUFFIX_TOKEN = "}}"; + String SUFFIX_TOKEN = "}}"; /** * Has the component been created as a default by {@link org.apache.camel.CamelContext} during starting up Camel. @@ -46,14 +46,16 @@ public interface PropertiesComponent extends Component, StaticService { /** * The value of the prefix token used to identify properties to replace. - * Is default {@link #DEFAULT_PREFIX_TOKEN} + * Is default {@link #PREFIX_TOKEN} */ + @Deprecated String getPrefixToken(); /** * The value of the suffix token used to identify properties to replace. - * Is default {@link #DEFAULT_SUFFIX_TOKEN} + * Is default {@link #SUFFIX_TOKEN} */ + @Deprecated String getSuffixToken(); /** diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java index 89f3e6a..583bb8f 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java @@ -1637,6 +1637,7 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext return answer; } + @Deprecated public String getPropertyPrefixToken() { PropertiesComponent pc = getPropertiesComponent(false); @@ -1647,6 +1648,7 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext } } + @Deprecated public String getPropertySuffixToken() { PropertiesComponent pc = getPropertiesComponent(false); @@ -1670,13 +1672,13 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext // it will handle that itself if (text != null && !text.startsWith("properties:")) { // No component, assume default tokens. - if (pc == null && text.contains(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { + if (pc == null && text.contains(PropertiesComponent.PREFIX_TOKEN)) { // lookup existing properties component, or force create a new // default component pc = getPropertiesComponent(true); } - if (pc != null && text.contains(pc.getPrefixToken())) { + if (pc != null && text.contains(PropertiesComponent.PREFIX_TOKEN)) { // the parser will throw exception if property key was not found String answer = pc.parseUri(text); log.debug("Resolved text: {} -> {}", text, answer); diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java index eaa87b4..0d24821 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java @@ -38,6 +38,7 @@ import org.apache.camel.ProxyInstantiationException; import org.apache.camel.RuntimeCamelException; import org.apache.camel.Service; import org.apache.camel.spi.BeanProxyFactory; +import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.support.CamelContextHelper; import org.apache.camel.support.IntrospectionSupport; import org.apache.camel.support.service.ServiceHelper; @@ -272,8 +273,8 @@ public class CamelPostProcessorHelper implements CamelContextAware { getCamelContext().getPropertiesComponent(true); String key; - String prefix = getCamelContext().getPropertyPrefixToken(); - String suffix = getCamelContext().getPropertySuffixToken(); + String prefix = PropertiesComponent.PREFIX_TOKEN; + String suffix = PropertiesComponent.SUFFIX_TOKEN; if (!propertyName.contains(prefix)) { // must enclose the property name with prefix/suffix to have it resolved key = prefix + propertyName + suffix; diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java index ade05e4..541037d 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java @@ -37,6 +37,7 @@ import org.apache.camel.PropertyInject; import org.apache.camel.RuntimeCamelException; import org.apache.camel.TypeConverter; import org.apache.camel.spi.CamelBeanPostProcessor; +import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.spi.Registry; import org.apache.camel.support.DefaultEndpoint; import org.apache.camel.util.ReflectionHelper; @@ -449,7 +450,7 @@ public class DefaultCamelBeanPostProcessor implements CamelBeanPostProcessor { key = key + ":" + pi.defaultValue(); } // need to force property lookup by having key enclosed in tokens - key = camelContext.getPropertiesComponent().getPrefixToken() + key + camelContext.getPropertiesComponent().getSuffixToken(); + key = PropertiesComponent.PREFIX_TOKEN + key + PropertiesComponent.SUFFIX_TOKEN; try { Object value = camelContext.resolvePropertyPlaceholders(key); parameters[i] = camelContext.getTypeConverter().convertTo(type, value); 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 8f7c223..4fe09e1 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 @@ -648,9 +648,6 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex pc.setDefaultFallbackEnabled(def.getDefaultFallbackEnabled()); } - pc.setPrefixToken(def.getPrefixToken()); - pc.setSuffixToken(def.getSuffixToken()); - if (def.getFunctions() != null && !def.getFunctions().isEmpty()) { for (CamelPropertyPlaceholderFunctionDefinition function : def.getFunctions()) { String ref = function.getRef(); 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 801b1e6..62ac831 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 @@ -44,10 +44,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { private String propertiesParserRef; @XmlAttribute @Metadata(defaultValue = "true") private Boolean defaultFallbackEnabled; - @XmlAttribute @Metadata(defaultValue = "{{") - private String prefixToken; - @XmlAttribute @Metadata(defaultValue = "}}") - private String suffixToken; @XmlElement(name = "propertiesFunction") private List<CamelPropertyPlaceholderFunctionDefinition> functions; @XmlElement(name = "propertiesLocation") @@ -112,30 +108,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { this.ignoreMissingLocation = ignoreMissingLocation; } - public String getPrefixToken() { - return prefixToken; - } - - /** - * Sets the value of the prefix token used to identify properties to replace. Setting a value of - * {@code null} restores the default token {{ - */ - public void setPrefixToken(String prefixToken) { - this.prefixToken = prefixToken; - } - - public String getSuffixToken() { - return suffixToken; - } - - /** - * Sets the value of the suffix token used to identify properties to replace. Setting a value of - * {@code null} restores the default token }} - */ - public void setSuffixToken(String suffixToken) { - this.suffixToken = suffixToken; - } - public List<CamelPropertyPlaceholderFunctionDefinition> getFunctions() { return functions; } diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java index 19df7cc..420a7af 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java @@ -31,6 +31,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.NamedNode; import org.apache.camel.spi.ExecutorServiceManager; +import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.spi.RouteContext; import org.apache.camel.support.IntrospectionSupport; import org.apache.camel.support.PropertyBindingSupport; @@ -701,11 +702,8 @@ public final class ProcessorDefinitionHelper { // value must be enclosed with placeholder tokens String s = (String) value; - String prefixToken = camelContext.getPropertyPrefixToken(); - String suffixToken = camelContext.getPropertySuffixToken(); - if (prefixToken == null) { - throw new IllegalArgumentException("Property with name [" + local + "] uses property placeholders; however, no properties component is configured."); - } + String prefixToken = PropertiesComponent.PREFIX_TOKEN; + String suffixToken = PropertiesComponent.SUFFIX_TOKEN; if (!s.startsWith(prefixToken)) { s = prefixToken + s; 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 3dbfef8..1a890d6 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 @@ -65,36 +65,6 @@ public class PropertiesComponentTest extends ContextTestSupport { } @Test - public void testPropertiesComponentCustomTokens() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setPrefixToken("[["); - pc.setSuffixToken("]]"); - - assertEquals("[[", pc.getPrefixToken()); - assertEquals("]]", pc.getSuffixToken()); - - 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(); - - pc.setPrefixToken(null); - pc.setSuffixToken(null); - - assertEquals(PropertiesComponent.DEFAULT_PREFIX_TOKEN, pc.getPrefixToken()); - assertEquals(PropertiesComponent.DEFAULT_SUFFIX_TOKEN, pc.getSuffixToken()); - } - - @Test public void testPropertiesComponentTemplate() throws Exception { context.addRoutes(new RouteBuilder() { @Override diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java index e428d5e..e742c0e 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java @@ -775,8 +775,8 @@ public final class IntrospectionSupport { if (context != null) { PropertiesComponent pc = context.getPropertiesComponent(false); if (pc != null) { - return value.toString().contains(pc.getPrefixToken()) - && value.toString().contains(pc.getSuffixToken()); + String text = value.toString(); + return text.contains(PropertiesComponent.PREFIX_TOKEN) && text.contains(PropertiesComponent.SUFFIX_TOKEN); } } return false; diff --git a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java index 07ab27d..49d501f 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java @@ -1486,7 +1486,7 @@ public class ExpressionBuilder { + " in CamelContext to support property placeholders in expressions"); } // enclose key with {{ }} to force parsing as key can be a nested expression too - return pc.parseUri(pc.getPrefixToken() + text + pc.getSuffixToken()); + return pc.parseUri(PropertiesComponent.PREFIX_TOKEN + text + PropertiesComponent.SUFFIX_TOKEN); } catch (Exception e) { // property with key not found, use default value if provided if (defaultValue != null) { 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 3951b3a..ed5f9b1 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 @@ -73,18 +73,6 @@ public class PropertiesComponentConfiguration */ private Boolean ignoreMissingLocation = false; /** - * 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). - */ - private String prefixToken = "{{"; - /** - * Sets the value of the suffix token used to identify properties to - * replace. Setting a value of null restores the default token (link - * DEFAULT_SUFFIX_TOKEN). - */ - private String suffixToken = "}}"; - /** * Sets initial properties which will be used before any locations are * resolved. The option is a java.util.Properties type. */ @@ -166,22 +154,6 @@ public class PropertiesComponentConfiguration this.ignoreMissingLocation = ignoreMissingLocation; } - public String getPrefixToken() { - return prefixToken; - } - - public void setPrefixToken(String prefixToken) { - this.prefixToken = prefixToken; - } - - public String getSuffixToken() { - return suffixToken; - } - - public void setSuffixToken(String suffixToken) { - this.suffixToken = suffixToken; - } - public String getInitialProperties() { return initialProperties; }