This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-13947 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4293fc237f7e8c4b986a40d018dd0c001f26d91b Author: Claus Ibsen <[email protected]> AuthorDate: Wed Sep 25 17:56:11 2019 +0200 CAMEL-13947: PropertiesComponent should be a static service and resolved like other similar features. --- .../component/properties/PropertiesComponent.java | 29 +- .../org/apache/camel/properties-component-factory | 18 + .../main/java/org/apache/camel/CamelContext.java | 7 +- .../org/apache/camel/spi/PropertiesComponent.java | 12 +- .../camel/impl/engine/AbstractCamelContext.java | 94 ++--- .../impl/engine/CamelPostProcessorHelper.java | 3 - .../engine/PropertiesComponentFactoryResolver.java | 72 ++++ .../simple/ast/SimpleFunctionExpression.java | 15 - .../org/apache/camel/impl/DefaultCamelContext.java | 7 + .../camel/model/ProcessorDefinitionHelper.java | 4 - .../camel/builder/xml/XPathFunctionsTest.java | 4 +- .../file/FilerProducerDoneFileNameRouteTest.java | 4 +- .../file/FilerProducerDoneFileNameTest.java | 5 +- .../ComponentResolvePropertyPlaceholdersTest.java | 6 +- .../OptionalPropertiesDslInvalidSyntaxTest.java | 4 +- .../properties/OptionalPropertiesDslTest.java | 4 +- ...onentAdviceWithInterceptSendToEndpointTest.java | 4 +- ...opertiesComponentConcatenatePropertiesTest.java | 4 +- .../PropertiesComponentDisableDefaultsTest.java | 7 +- ...pertiesComponentEIPChoiceConvertBodyToTest.java | 6 +- .../PropertiesComponentEIPChoiceSimpleTest.java | 6 +- .../PropertiesComponentEIPConvertBodyToTest.java | 6 +- .../PropertiesComponentEIPRoutingSlipTest.java | 6 +- .../PropertiesComponentEncodingTest.java | 6 +- .../PropertiesComponentEndpointTest.java | 6 +- .../PropertiesComponentFunctionTest.java | 2 +- .../PropertiesComponentGetOrElseTest.java | 4 +- .../PropertiesComponentInitialPropertiesTest.java | 4 +- .../PropertiesComponentInterceptFromTest.java | 6 +- ...ertiesComponentInterceptSendToEndpointTest.java | 4 +- ...ponentLoadPropertiesFromFileTrimValuesTest.java | 4 +- .../PropertiesComponentLoadPropertiesTest.java | 4 +- .../PropertiesComponentNestPropertiesTest.java | 4 +- ...ertiesComponentOnExceptionDelayPatternTest.java | 6 +- .../PropertiesComponentOnExceptionTest.java | 6 +- ...esComponentOverridePropertiesNonStringTest.java | 6 +- .../PropertiesComponentOverridePropertiesTest.java | 6 +- .../PropertiesComponentPropertiesSourceTest.java | 14 +- .../properties/PropertiesComponentRefTest.java | 6 +- .../PropertiesComponentRegistryTest.java | 4 +- .../PropertiesComponentSetHeaderSimpleTest.java | 6 +- .../PropertiesComponentSimpleLanguageTest.java | 6 +- .../properties/PropertiesComponentTest.java | 446 --------------------- .../PropertiesEnvironmentVariableOverrideTest.java | 6 +- .../properties/PropertiesRouteFromTest.java | 4 +- .../properties/PropertiesRouteIdTest.java | 4 +- .../properties/XPathPropertyPlaceholderTest.java | 2 +- .../impl/engine/CamelPostProcessorHelperTest.java | 6 +- .../issues/PropertiesAvailableEverywhereTest.java | 4 +- .../TransactedPropertyPlaceholderIssueTest.java | 6 +- ...LWithDotInParameterPropertyPlaceholderTest.java | 6 +- .../PropertyInjectAnnotationParameterTest.java | 5 +- .../simple/SimplePropertiesNestedTest.java | 6 +- .../language/simple/SimpleWithPropertiesTest.java | 3 - .../camel/processor/RouteAutoStartupTest.java | 10 +- .../camel/processor/SimpleMockPlaceholderTest.java | 5 +- .../InterceptFromPropertyPlaceholderTest.java | 6 +- .../support/jsse/AbstractJsseParametersTest.java | 8 +- ...mlChoiceFilterRoutePropertyPlaceholderTest.java | 3 +- .../camel/util/DumpModelAsXmlPlaceholdersTest.java | 4 +- .../apache/camel/support/IntrospectionSupport.java | 7 +- .../camel/support/builder/ExpressionBuilder.java | 29 -- 62 files changed, 211 insertions(+), 790 deletions(-) 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 8b83d12..3f2e45f 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 @@ -27,8 +27,8 @@ import java.util.Properties; import java.util.function.Predicate; import java.util.stream.Collectors; +import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; -import org.apache.camel.Endpoint; import org.apache.camel.ExtendedCamelContext; import org.apache.camel.NoFactoryAvailableException; import org.apache.camel.StaticService; @@ -38,23 +38,20 @@ import org.apache.camel.spi.FactoryFinder; import org.apache.camel.spi.LoadablePropertiesSource; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.PropertiesSource; -import org.apache.camel.spi.annotations.Component; -import org.apache.camel.support.DefaultComponent; import org.apache.camel.support.OrderedComparator; import org.apache.camel.support.service.ServiceHelper; +import org.apache.camel.support.service.ServiceSupport; import org.apache.camel.util.FilePathResolver; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.OrderedProperties; -import org.apache.camel.util.URISupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The <a href="http://camel.apache.org/properties">Properties Component</a> allows you to use property placeholders when defining Endpoint URIs */ -@Component("properties") @ManagedResource(description = "Managed PropertiesComponent") -public class PropertiesComponent extends DefaultComponent implements org.apache.camel.spi.PropertiesComponent, StaticService { +public class PropertiesComponent extends ServiceSupport implements org.apache.camel.spi.PropertiesComponent, StaticService, CamelContextAware { /** * Never check system properties. @@ -102,6 +99,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. private static final Logger LOG = LoggerFactory.getLogger(PropertiesComponent.class); + private CamelContext camelContext; private final Map<String, PropertiesFunction> functions = new LinkedHashMap<>(); private PropertiesParser propertiesParser = new DefaultPropertiesParser(this); private final PropertiesLookup propertiesLookup = new DefaultPropertiesLookup(this); @@ -155,17 +153,13 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. } @Override - protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - String endpointUri = parseUri(remaining); - if (LOG.isDebugEnabled()) { - log.debug("Endpoint uri parsed as: {}", URISupport.sanitizeUri(endpointUri)); - } - - Endpoint delegate = getCamelContext().getEndpoint(endpointUri); - PropertiesEndpoint answer = new PropertiesEndpoint(uri, delegate, this); + public CamelContext getCamelContext() { + return camelContext; + } - setProperties(answer, parameters); - return answer; + @Override + public void setCamelContext(CamelContext camelContext) { + this.camelContext = camelContext; } @Override @@ -371,6 +365,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. * If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) * as documented by {@link java.util.Properties#load(java.io.InputStream)} */ + @Override public void setEncoding(String encoding) { this.encoding = encoding; } @@ -576,6 +571,8 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. @Override protected void doStart() throws Exception { + ObjectHelper.notNull(camelContext, "CamelContext", this); + sources.sort(OrderedComparator.get()); ServiceHelper.startService(sources); diff --git a/components/camel-properties/src/main/resources/META-INF/services/org/apache/camel/properties-component-factory b/components/camel-properties/src/main/resources/META-INF/services/org/apache/camel/properties-component-factory new file mode 100644 index 0000000..9f34c8f --- /dev/null +++ b/components/camel-properties/src/main/resources/META-INF/services/org/apache/camel/properties-component-factory @@ -0,0 +1,18 @@ +# +# 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. +# + +class=org.apache.camel.component.properties.PropertiesComponent 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 8e501f6..f86b7a0 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 @@ -749,12 +749,9 @@ public interface CamelContext extends StatefulService, RuntimeConfiguration { PropertiesComponent getPropertiesComponent(); /** - * Returns the configured properties component or create one if none has been configured. - * - * @param autoCreate whether the component should be created if none is configured - * @return the properties component + * Sets a custom properties component to be used. */ - PropertiesComponent getPropertiesComponent(boolean autoCreate); + void setPropertiesComponent(PropertiesComponent propertiesComponent); /** * Gets a readonly list with the names of the languages currently registered. 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 d92ed2a..362497b 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 @@ -21,14 +21,13 @@ import java.util.Optional; import java.util.Properties; import java.util.function.Predicate; -import org.apache.camel.Component; import org.apache.camel.StaticService; /** * Component for property placeholders and loading properties from sources * (such as .properties file from classpath or file system) */ -public interface PropertiesComponent extends Component, StaticService { +public interface PropertiesComponent extends StaticService { /** * The prefix token. @@ -43,6 +42,7 @@ public interface PropertiesComponent extends Component, StaticService { /** * Has the component been created as a default by {@link org.apache.camel.CamelContext} during starting up Camel. */ + @Deprecated String DEFAULT_CREATED = "PropertiesComponentDefaultCreated"; /** @@ -121,4 +121,12 @@ public interface PropertiesComponent extends Component, StaticService { */ void setOverrideProperties(Properties overrideProperties); + /** + * Encoding to use when loading properties file from the file system or classpath. + * <p/> + * If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) + * as documented by {@link java.util.Properties#load(java.io.InputStream)} + */ + void setEncoding(String encoding); + } 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 56eac80..7d81b11 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 @@ -149,6 +149,7 @@ import org.apache.camel.support.service.ServiceHelper; import org.apache.camel.support.service.ServiceSupport; import org.apache.camel.util.IOHelper; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.PropertiesHelper; import org.apache.camel.util.StopWatch; import org.apache.camel.util.StringHelper; import org.apache.camel.util.TimeUtils; @@ -1650,30 +1651,11 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext @Override public String resolvePropertyPlaceholders(String text) { - // While it is more efficient to only do the lookup if we are sure we - // need the component, - // with custom tokens, we cannot know if the URI contains a property or - // not without having - // the component. We also lose fail-fast behavior for the missing - // component with this change. - PropertiesComponent pc = getPropertiesComponent(false); - - // Do not parse uris that are designated for the properties component as - // it will handle that itself - if (text != null && !text.startsWith("properties:")) { - // No component, assume default tokens. - 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(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); - return answer; - } + if (text != null && text.contains(PropertiesComponent.PREFIX_TOKEN)) { + // the parser will throw exception if property key was not found + String answer = getPropertiesComponent().parseUri(text); + log.debug("Resolved text: {} -> {}", text, answer); + return answer; } // return original text as is @@ -1738,6 +1720,23 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext } @Override + public PropertiesComponent getPropertiesComponent() { + if (propertiesComponent == null) { + synchronized (lock) { + if (propertiesComponent == null) { + setPropertiesComponent(createPropertiesComponent()); + } + } + } + return propertiesComponent; + } + + @Override + public void setPropertiesComponent(PropertiesComponent propertiesComponent) { + this.propertiesComponent = doAddService(propertiesComponent); + } + + @Override public CamelBeanPostProcessor getBeanPostProcessor() { if (beanPostProcessor == null) { synchronized (lock) { @@ -2582,16 +2581,6 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext addService(runtimeEndpointRegistry, true, true); } - // eager lookup any configured properties component to avoid subsequent - // lookup attempts which may impact performance - // due we use properties component for property placeholder resolution - // at runtime - PropertiesComponent existing = getPropertiesComponent(false); - if (existing != null) { - // store reference to the existing properties component - propertiesComponent = existing; - } - bindDataFormats(); // start components @@ -3318,6 +3307,7 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext getRestRegistryFactory(); getReactiveExecutor(); getBeanIntrospection(); + getPropertiesComponent(); if (isTypeConverterStatisticsEnabled() != null) { getTypeConverterRegistry().getStatistics().setStatisticsEnabled(isTypeConverterStatisticsEnabled()); @@ -3399,40 +3389,6 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext return isStarted() && !isStarting(); } - /** - * Gets the properties component in use, eventually creating it. - */ - @Override - public PropertiesComponent getPropertiesComponent() { - return getPropertiesComponent(true); - } - - @Override - public PropertiesComponent getPropertiesComponent(boolean autoCreate) { - if (propertiesComponent == null && autoCreate) { - Object comp = ResolverHelper.lookupComponentInRegistryWithFallback(this, "properties"); - if (comp == null) { - try { - comp = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH).newInstance("properties").orElse(null); - } catch (NoFactoryAvailableException e) { - // ignore - } - if (comp != null) { - log.debug("No existing PropertiesComponent has been configured, created a new default PropertiesComponent with name: properties"); - globalOptions.put(PropertiesComponent.DEFAULT_CREATED, "true"); - } - } - if (comp instanceof PropertiesComponent) { - addComponent("properties", (PropertiesComponent) comp); - // this adds comp as properties component and sets this.propertiesComponent = comp - } - if (propertiesComponent == null) { - throw new IllegalStateException("Cannot auto create Properties component"); - } - } - return propertiesComponent; - } - @Override public Map<String, String> getGlobalOptions() { return globalOptions; @@ -4185,6 +4141,8 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext protected abstract Injector createInjector(); + protected abstract PropertiesComponent createPropertiesComponent(); + protected abstract CamelBeanPostProcessor createBeanPostProcessor(); protected abstract ComponentResolver createComponentResolver(); 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 c6e65dd..156062f 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 @@ -258,9 +258,6 @@ public class CamelPostProcessorHelper implements CamelContextAware { public Object getInjectionPropertyValue(Class<?> type, String propertyName, String propertyDefaultValue, String injectionPointName, Object bean, String beanName) { try { - // enforce a properties component to be created if none existed - getCamelContext().getPropertiesComponent(true); - String key; String prefix = PropertiesComponent.PREFIX_TOKEN; String suffix = PropertiesComponent.SUFFIX_TOKEN; diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/PropertiesComponentFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/PropertiesComponentFactoryResolver.java new file mode 100644 index 0000000..1407e83 --- /dev/null +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/PropertiesComponentFactoryResolver.java @@ -0,0 +1,72 @@ +/* + * 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.impl.engine; + +import java.io.IOException; + +import org.apache.camel.CamelContext; +import org.apache.camel.ExtendedCamelContext; +import org.apache.camel.spi.FactoryFinder; +import org.apache.camel.spi.PropertiesComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Factory resolver to find the {@link org.apache.camel.spi.PropertiesComponent} from the classpath in camel-properties. + */ +public class PropertiesComponentFactoryResolver { + + public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; + + private static final Logger LOG = LoggerFactory.getLogger(PropertiesComponentFactoryResolver.class); + + private FactoryFinder factoryFinder; + + public PropertiesComponent resolve(CamelContext context) { + // use factory finder to find a custom implementations + Class<?> type = null; + try { + type = findFactory("properties-component-factory", context); + } catch (Exception e) { + // ignore + } + + if (type != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Found PropertiesComponent: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "properties-component-factory"); + } + if (PropertiesComponent.class.isAssignableFrom(type)) { + PropertiesComponent answer = (PropertiesComponent) context.getInjector().newInstance(type, false); + LOG.debug("Detected and using PropertiesComponent: {}", answer); + return answer; + } else { + throw new IllegalArgumentException("Type is not a PropertiesComponent implementation. Found: " + type.getName()); + } + } + + LOG.debug("Cannot find PropertiesComponent. Make sure camel-properties is on the classpath."); + return null; + } + + private Class<?> findFactory(String name, CamelContext context) throws IOException { + if (factoryFinder == null) { + factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); + } + return factoryFinder.findClass(name).orElse(null); + } + +} diff --git a/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java b/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java index adabcdc..d6eab1f 100644 --- a/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java +++ b/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java @@ -208,21 +208,6 @@ public class SimpleFunctionExpression extends LiteralExpression { return ExpressionBuilder.beanExpression(remainder); } - // properties: prefix - remainder = ifStartsWithReturnRemainder("properties:", function); - if (remainder != null) { - String[] parts = remainder.split(":"); - if (parts.length > 2) { - throw new SimpleParserException("Valid syntax: ${properties:key[:default]} was: " + function, token.getIndex()); - } - String defaultValue = null; - if (parts.length >= 2) { - defaultValue = parts[1]; - } - String key = parts[0]; - return ExpressionBuilder.propertiesComponentExpression(key, defaultValue); - } - // ref: prefix remainder = ifStartsWithReturnRemainder("ref:", function); if (remainder != null) { diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index d2c370b..fd66e87 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -53,6 +53,7 @@ import org.apache.camel.impl.engine.DefaultUnitOfWorkFactory; import org.apache.camel.impl.engine.DefaultUuidGenerator; import org.apache.camel.impl.engine.EndpointKey; import org.apache.camel.impl.engine.HeadersMapFactoryResolver; +import org.apache.camel.impl.engine.PropertiesComponentFactoryResolver; import org.apache.camel.impl.engine.ReactiveExecutorResolver; import org.apache.camel.impl.engine.RestRegistryFactoryResolver; import org.apache.camel.impl.engine.ServicePool; @@ -84,6 +85,7 @@ import org.apache.camel.spi.ModelJAXBContextFactory; import org.apache.camel.spi.NodeIdFactory; import org.apache.camel.spi.PackageScanClassResolver; import org.apache.camel.spi.ProcessorFactory; +import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.spi.ReactiveExecutor; import org.apache.camel.spi.Registry; import org.apache.camel.spi.RestRegistryFactory; @@ -180,6 +182,11 @@ public class DefaultCamelContext extends AbstractModelCamelContext { } @Override + protected PropertiesComponent createPropertiesComponent() { + return new PropertiesComponentFactoryResolver().resolve(this); + } + + @Override protected CamelBeanPostProcessor createBeanPostProcessor() { return new DefaultCamelBeanPostProcessor(this); } diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java index bc63220..fbb95d6 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java @@ -764,10 +764,6 @@ public final class ProcessorDefinitionHelper { other.forEach((k, v) -> { if (Constants.PLACEHOLDER_QNAME.equals(k.getNamespaceURI())) { if (v instanceof String) { - // enforce a properties component to be created if - // none existed - camelContext.getPropertiesComponent(true); - // value must be enclosed with placeholder tokens String s = (String)v; String prefixToken = PropertiesComponent.PREFIX_TOKEN; diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFunctionsTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFunctionsTest.java index 774c287..b6d3acc 100644 --- a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFunctionsTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFunctionsTest.java @@ -64,9 +64,7 @@ public class XPathFunctionsTest extends ContextTestSupport { public void configure() throws Exception { // START SNIPPET: ex // setup properties component - PropertiesComponent properties = new PropertiesComponent(); - properties.setLocation("classpath:org/apache/camel/builder/xml/myprop.properties"); - context.addComponent("properties", properties); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/builder/xml/myprop.properties"); // myprop.properties contains the following properties // foo=Camel diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameRouteTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameRouteTest.java index fb826ae..c0cd5a2 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameRouteTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameRouteTest.java @@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.impl.JndiRegistry; import org.junit.Before; import org.junit.Test; @@ -73,8 +72,7 @@ public class FilerProducerDoneFileNameRouteTest extends ContextTestSupport { public void configure() throws Exception { myProp.put("myDir", "target/data/done"); - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setLocation("ref:myProp"); + context.getPropertiesComponent().setLocation("ref:myProp"); from("direct:start").to("file:{{myDir}}?doneFileName=done-${file:name}").to("mock:result"); } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java index e5af55f..d2985dd 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerDoneFileNameTest.java @@ -53,10 +53,7 @@ public class FilerProducerDoneFileNameTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setLocation("ref:myProp"); - + context.getPropertiesComponent().setLocation("ref:myProp"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/ComponentResolvePropertyPlaceholdersTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/ComponentResolvePropertyPlaceholdersTest.java index 2290b0b..f2392f5 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/ComponentResolvePropertyPlaceholdersTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/ComponentResolvePropertyPlaceholdersTest.java @@ -57,11 +57,7 @@ public class ComponentResolvePropertyPlaceholdersTest extends ContextTestSupport @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java index 0b1dd77..df2312c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java @@ -71,9 +71,7 @@ public class OptionalPropertiesDslInvalidSyntaxTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslTest.java index bb481e4..20b8617 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslTest.java @@ -61,9 +61,7 @@ public class OptionalPropertiesDslTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentAdviceWithInterceptSendToEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentAdviceWithInterceptSendToEndpointTest.java index 556465a..0181226 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentAdviceWithInterceptSendToEndpointTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentAdviceWithInterceptSendToEndpointTest.java @@ -56,9 +56,7 @@ public class PropertiesComponentAdviceWithInterceptSendToEndpointTest extends Co @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java index 68b0419..85adbe3 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentConcatenatePropertiesTest.java @@ -27,9 +27,7 @@ public class PropertiesComponentConcatenatePropertiesTest extends ContextTestSup @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/concatenation.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/concatenation.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java index eb4e49e..8e510d5 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDisableDefaultsTest.java @@ -57,10 +57,9 @@ public class PropertiesComponentDisableDefaultsTest extends ContextTestSupport { props.put("p:mockend", "end"); props.put("p:message", "my message"); - PropertiesComponent component = new PropertiesComponent(); - component.setDefaultFallbackEnabled(false); - component.setInitialProperties(props); - context.addComponent("properties", component); + PropertiesComponent pc = (PropertiesComponent) context.getPropertiesComponent(); + pc.setDefaultFallbackEnabled(false); + pc.setInitialProperties(props); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceConvertBodyToTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceConvertBodyToTest.java index c095bf5..3eecab3 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceConvertBodyToTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceConvertBodyToTest.java @@ -60,11 +60,7 @@ public class PropertiesComponentEIPChoiceConvertBodyToTest extends ContextTestSu @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"classpath:org/apache/camel/component/properties/myproperties.properties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceSimpleTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceSimpleTest.java index d23b900..f1b0294 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceSimpleTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPChoiceSimpleTest.java @@ -48,11 +48,7 @@ public class PropertiesComponentEIPChoiceSimpleTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"classpath:org/apache/camel/component/properties/myproperties.properties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPConvertBodyToTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPConvertBodyToTest.java index 14415d5..55ea37c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPConvertBodyToTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPConvertBodyToTest.java @@ -49,11 +49,7 @@ public class PropertiesComponentEIPConvertBodyToTest extends ContextTestSupport @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"classpath:org/apache/camel/component/properties/myproperties.properties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPRoutingSlipTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPRoutingSlipTest.java index a9868ed..89b9c29 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPRoutingSlipTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEIPRoutingSlipTest.java @@ -46,11 +46,7 @@ public class PropertiesComponentEIPRoutingSlipTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"classpath:org/apache/camel/component/properties/myproperties.properties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEncodingTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEncodingTest.java index 83c3323..c216e65 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEncodingTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEncodingTest.java @@ -47,10 +47,8 @@ public class PropertiesComponentEncodingTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent prop = new PropertiesComponent(); - prop.setLocation("classpath:org/apache/camel/component/properties/myutf8.properties"); - prop.setEncoding("UTF-8"); - context.addComponent("properties", prop); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myutf8.properties"); + context.getPropertiesComponent().setEncoding("UTF-8"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java index 63e7944..1e48de9 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentEndpointTest.java @@ -65,11 +65,7 @@ public class PropertiesComponentEndpointTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java index c959c1b..a110c26 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java @@ -42,7 +42,7 @@ public class PropertiesComponentFunctionTest extends ContextTestSupport { @Test public void testFunction() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); + PropertiesComponent pc = (PropertiesComponent) context.getPropertiesComponent(); pc.addFunction(new MyFunction()); context.addRoutes(new RouteBuilder() { diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentGetOrElseTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentGetOrElseTest.java index 49c6a69..f21bf80 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentGetOrElseTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentGetOrElseTest.java @@ -93,9 +93,7 @@ public class PropertiesComponentGetOrElseTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java index 4ffad9b..27cecd2 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInitialPropertiesTest.java @@ -21,6 +21,7 @@ import java.util.Properties; import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.PropertiesComponent; import org.junit.Test; public class PropertiesComponentInitialPropertiesTest extends ContextTestSupport { @@ -53,9 +54,8 @@ public class PropertiesComponentInitialPropertiesTest extends ContextTestSupport protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); + PropertiesComponent pc = context.getPropertiesComponent(); pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); Properties initial = new Properties(); initial.put("first", "mock:first"); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptFromTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptFromTest.java index 616d485..a3a921c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptFromTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptFromTest.java @@ -37,11 +37,7 @@ public class PropertiesComponentInterceptFromTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptSendToEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptSendToEndpointTest.java index f47e42d..ba7c603 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptSendToEndpointTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentInterceptSendToEndpointTest.java @@ -48,9 +48,7 @@ public class PropertiesComponentInterceptSendToEndpointTest extends ContextTestS @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java index 3e4b138..36f5d31 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java @@ -56,9 +56,7 @@ public class PropertiesComponentLoadPropertiesFromFileTrimValuesTest extends Con fos.close(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("file:target/data/space/space.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("file:target/data/space/space.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesTest.java index 06917be..ca2e738 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesTest.java @@ -46,9 +46,7 @@ public class PropertiesComponentLoadPropertiesTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentNestPropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentNestPropertiesTest.java index 876e709..298e59f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentNestPropertiesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentNestPropertiesTest.java @@ -28,9 +28,7 @@ public class PropertiesComponentNestPropertiesTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/adapter.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/adapter.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionDelayPatternTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionDelayPatternTest.java index 17ac536..f9a9c48 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionDelayPatternTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionDelayPatternTest.java @@ -47,11 +47,7 @@ public class PropertiesComponentOnExceptionDelayPatternTest extends ContextTestS @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"classpath:org/apache/camel/component/properties/myproperties.properties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionTest.java index 18659a8..ac13d66 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnExceptionTest.java @@ -72,11 +72,7 @@ public class PropertiesComponentOnExceptionTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"ref:myprop"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("ref:myprop"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesNonStringTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesNonStringTest.java index 9537b23..564bc4f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesNonStringTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesNonStringTest.java @@ -53,14 +53,12 @@ public class PropertiesComponentOverridePropertiesNonStringTest extends ContextT protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); Properties extra = new Properties(); extra.put("cool.result", 123); extra.put("hey", "mock:hey"); - pc.setOverrideProperties(extra); + context.getPropertiesComponent().setOverrideProperties(extra); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesTest.java index 02a2334..beab3b7 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesTest.java @@ -53,14 +53,12 @@ public class PropertiesComponentOverridePropertiesTest extends ContextTestSuppor protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); Properties extra = new Properties(); extra.put("cool.result", "extra"); extra.put("hey", "mock:hey"); - pc.setOverrideProperties(extra); + context.getPropertiesComponent().setOverrideProperties(extra); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentPropertiesSourceTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentPropertiesSourceTest.java index 2ac425c..e87430b 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentPropertiesSourceTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentPropertiesSourceTest.java @@ -45,8 +45,7 @@ public class PropertiesComponentPropertiesSourceTest { context.getRegistry().bind("my-ps-1", new PropertiesPropertiesSource(Ordered.HIGHEST, "ps1", "shared", "v1", "my-key-1", "my-val-1")); context.getRegistry().bind("my-ps-2", new PropertiesPropertiesSource(Ordered.LOWEST, "ps2", "shared", "v2", "my-key-2", "my-val-2")); - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - Properties properties = pc.loadProperties(); + Properties properties = context.getPropertiesComponent().loadProperties(); assertThat(properties.get("my-key-1")).isEqualTo("my-val-1"); assertThat(properties.get("my-key-2")).isEqualTo("my-val-2"); @@ -64,10 +63,9 @@ public class PropertiesComponentPropertiesSourceTest { context.getRegistry().bind("my-ps-1", new PropertiesPropertiesSource("ps1", "my-key-1", "my-val-1")); context.getRegistry().bind("my-ps-2", new PropertiesPropertiesSource("ps2", "my-key-2", "my-val-2")); - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setInitialProperties(initial); + context.getPropertiesComponent().setInitialProperties(initial); - Properties properties = pc.loadProperties(k -> k.endsWith("-2")); + Properties properties = context.getPropertiesComponent().loadProperties(k -> k.endsWith("-2")); assertThat(properties).hasSize(2); assertThat(properties.get("initial-2")).isEqualTo("initial-val-2"); @@ -76,11 +74,11 @@ public class PropertiesComponentPropertiesSourceTest { @Test public void testDisablePropertiesSourceDiscovery() { - PropertiesComponent pc = new PropertiesComponent(); - pc.setAutoDiscoverPropertiesSources(false); CamelContext context = new DefaultCamelContext(); - context.addComponent("properties", pc); + PropertiesComponent pc = (PropertiesComponent) context.getPropertiesComponent(); + pc.setAutoDiscoverPropertiesSources(false); + context.getRegistry().bind("my-ps-1", new PropertiesPropertiesSource("ps1", "my-key-1", "my-val-1")); context.getRegistry().bind("my-ps-2", new PropertiesPropertiesSource("ps2", "my-key-2", "my-val-2")); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRefTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRefTest.java index 2b4d41a..9dc4c3f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRefTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRefTest.java @@ -69,11 +69,7 @@ public class PropertiesComponentRefTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"ref:myCoolProperties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("ref:myCoolProperties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java index 4c97045..a480f57 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java @@ -48,9 +48,7 @@ public class PropertiesComponentRegistryTest extends ContextTestSupport { reg.bind("bar", bar); context.setRegistry(reg); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSetHeaderSimpleTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSetHeaderSimpleTest.java index 5f7057c..381b329 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSetHeaderSimpleTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSetHeaderSimpleTest.java @@ -35,11 +35,7 @@ public class PropertiesComponentSetHeaderSimpleTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSimpleLanguageTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSimpleLanguageTest.java index 19f24d2..d12d7ad 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSimpleLanguageTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentSimpleLanguageTest.java @@ -59,11 +59,7 @@ public class PropertiesComponentSimpleLanguageTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); return context; } 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 deleted file mode 100644 index 1908fe6..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java +++ /dev/null @@ -1,446 +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.apache.camel.CamelContext; -import org.apache.camel.ContextTestSupport; -import org.apache.camel.ResolveEndpointFailedException; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class PropertiesComponentTest extends ContextTestSupport { - - @Override - public boolean isUseRouteBuilder() { - return false; - } - - @Test - public void testPropertiesComponent() throws Exception { - 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 testPropertiesComponentTwo() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:{{cool.end}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2); - - template.sendBody("direct:start", "Hello World"); - template.sendBody("direct:start", "Bye World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentTemplate() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:cool").to("mock:result"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2); - - template.sendBody("{{cool.start}}", "Hello World"); - template.sendBody("{{cool.start}}", "Bye World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentResult() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:mock:{{cool.result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(1); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentMockMock() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:{{cool.mock}}:{{cool.mock}}"); - } - }); - context.start(); - - getMockEndpoint("mock:mock").expectedMessageCount(1); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentConcat() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool.concat"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(1); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentInvalidKey() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:{{foo.unknown}}"); - } - }); - 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 [foo.unknown] not found in properties from text: {{foo.unknown}}", iae.getMessage()); - } - } - - @Test - public void testPropertiesComponentCircularReference() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").to("properties:cool.a"); - } - }); - 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("Circular reference detected with key [cool.a] from text: {{cool.a}}", iae.getMessage()); - } - } - - @Test - public void testPropertiesComponentCacheDefault() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // properties component can also have {{ }} around but its not - // needed - from("direct:start").to("properties:{{cool.end}}"); - from("direct:foo").to("properties:mock:{{cool.result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2); - - template.sendBody("direct:start", "Hello World"); - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testManyParseUri() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - assertNotNull(pc); - - for (int i = 0; i < 2000; i++) { - String uri = pc.parseUri("{{cool.mock}}:" + i); - assertEquals("mock:" + i, uri); - } - } - - @Test - public void testManySendMessages() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").setBody(simple("${properties:cool.mock}${body}")).to("mock:result"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(2000); - - for (int i = 0; i < 2000; i++) { - template.sendBody("direct:start", i); - } - - assertMockEndpointsSatisfied(); - } - - @Test - public void testQuotedPrefix() throws Exception { - assertEquals("mock", context.resolvePropertyPlaceholders("{{cool.mock}}")); - assertEquals("'{{' + something + '}}'", context.resolvePropertyPlaceholders("'{{' + something + '}}'")); - assertEquals("\"{{\" + something + \"}}\"", context.resolvePropertyPlaceholders("\"{{\" + something + \"}}\"")); - assertEquals("mock'", context.resolvePropertyPlaceholders("{{cool.mock}}'")); - assertEquals("mock\"", context.resolvePropertyPlaceholders("{{cool.mock}}\"")); - assertEquals("'mock", context.resolvePropertyPlaceholders("'{{cool.mock}}")); - assertEquals("\"mock", context.resolvePropertyPlaceholders("\"{{cool.mock}}")); - } - - @Test - public void testPropertiesComponentOverride() throws Exception { - System.setProperty("cool.result", "bar"); - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_OVERRIDE); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:foo").to("mock:{{cool.result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(0); - getMockEndpoint("mock:bar").expectedMessageCount(1); - - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - - System.clearProperty("cool.result"); - } - - @Test - public void testPropertiesComponentFallback() throws Exception { - System.setProperty("cool.result", "bar"); - System.setProperty("beer", "Carlsberg"); - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_FALLBACK); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:foo").to("mock:{{beer}}").to("mock:{{cool.result}}"); - } - }); - context.start(); - - getMockEndpoint("mock:result").expectedMessageCount(1); - getMockEndpoint("mock:bar").expectedMessageCount(0); - getMockEndpoint("mock:Carlsberg").expectedMessageCount(1); - - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - - System.clearProperty("cool.result"); - System.clearProperty("beer"); - } - - @Test - public void testPropertiesComponentNever() throws Exception { - System.setProperty("cool.result", "bar"); - System.setProperty("beer", "Carlsberg"); - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_NEVER); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:foo").to("mock:{{beer}}").to("mock:{{cool.result}}"); - } - }); - try { - context.start(); - fail("Should have thrown exception"); - } catch (Exception e) { - assertEquals("Property with key [beer] not found in properties from text: mock:{{beer}}", e.getCause().getMessage()); - } - - System.clearProperty("cool.result"); - System.clearProperty("beer"); - } - - @Test - public void testPropertiesComponentEnvOverride() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setEnvironmentVariableMode(PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_OVERRIDE); - pc.setLocation("org/apache/camel/component/properties/env.properties"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:foo").to("mock:{{FOO_SERVICE_HOST}}"); - } - }); - context.start(); - - getMockEndpoint("mock:hello").expectedMessageCount(0); - getMockEndpoint("mock:myserver").expectedMessageCount(1); - - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentEnvOverrideIfDash() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setEnvironmentVariableMode(PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_OVERRIDE); - pc.setLocation("org/apache/camel/component/properties/env.properties"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // will fallback and lookup as FOO_SERVICE_HOST - from("direct:foo").to("mock:{{FOO-SERVICE_host}}"); - } - }); - context.start(); - - getMockEndpoint("mock:hello").expectedMessageCount(0); - getMockEndpoint("mock:myserver").expectedMessageCount(1); - - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentEnvFallback() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setEnvironmentVariableMode(PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_FALLBACK); - pc.setLocation("org/apache/camel/component/properties/env.properties"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:foo").to("mock:{{FOO_SERVICE_PORT}}"); - } - }); - context.start(); - - getMockEndpoint("mock:8081").expectedMessageCount(1); - getMockEndpoint("mock:hello").expectedMessageCount(0); - getMockEndpoint("mock:myserver").expectedMessageCount(0); - - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testPropertiesComponentEnvNever() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setEnvironmentVariableMode(PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_NEVER); - pc.setLocation("org/apache/camel/component/properties/env.properties"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:foo").to("mock:{{UNKNOWN}}"); - } - }); - try { - context.start(); - fail("Should have thrown exception"); - } catch (Exception e) { - assertEquals("Property with key [UNKNOWN] not found in properties from text: mock:{{UNKNOWN}}", e.getCause().getMessage()); - } - } - - @Test - public void testPropertiesComponentEnvFallbackJvmOverride() throws Exception { - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setEnvironmentVariableMode(PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_FALLBACK); - pc.setLocation("org/apache/camel/component/properties/env.properties"); - - // lets override the OS environment variable by setting a JVM system - // property - System.setProperty("FOO_SERVICE_PORT", "hello"); - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:foo").to("mock:{{FOO_SERVICE_PORT}}"); - } - }); - context.start(); - - getMockEndpoint("mock:8081").expectedMessageCount(0); - getMockEndpoint("mock:hello").expectedMessageCount(1); - getMockEndpoint("mock:myserver").expectedMessageCount(0); - - template.sendBody("direct:foo", "Hello Foo"); - - assertMockEndpointsSatisfied(); - - System.clearProperty("FOO_SERVICE_PORT"); - } - - @Test - public void testCamelProperties() throws Exception { - context.getGlobalOptions().put("foo", "Hello {{cool.name}}"); - context.getGlobalOptions().put("bar", "cool.name"); - - context.start(); - - assertEquals("Hello Camel", context.getGlobalOptions().get("foo")); - assertEquals("cool.name", context.getGlobalOptions().get("bar")); - } - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); - return context; - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java index 341f104..fc1368b 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java @@ -56,11 +56,7 @@ public class PropertiesEnvironmentVariableOverrideTest extends ContextTestSuppor @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"classpath:org/apache/camel/component/properties/myproperties.properties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteFromTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteFromTest.java index 9ab1849..b2f0fb5 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteFromTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteFromTest.java @@ -56,9 +56,7 @@ public class PropertiesRouteFromTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteIdTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteIdTest.java index c1ac4fc..a5ef7e7 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteIdTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesRouteIdTest.java @@ -48,9 +48,7 @@ public class PropertiesRouteIdTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/XPathPropertyPlaceholderTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/XPathPropertyPlaceholderTest.java index 7c5ab05..ec26d05 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/properties/XPathPropertyPlaceholderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/XPathPropertyPlaceholderTest.java @@ -65,7 +65,7 @@ public class XPathPropertyPlaceholderTest extends ContextTestSupport { prop.put("foo", "//greeting/text = 'Hello, world!'"); prop.put("bar", "//greeting/text = 'Bye, world!'"); - PropertiesComponent pc = context.getPropertiesComponent(true); + PropertiesComponent pc = context.getPropertiesComponent(); pc.setInitialProperties(prop); from("direct:filter").filter().xpath("{{foo}}").log("Passed filter!").to("mock:output-filter"); diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java index dd798ab..cdbf5c0 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/engine/CamelPostProcessorHelperTest.java @@ -37,7 +37,6 @@ import org.apache.camel.PropertyInject; import org.apache.camel.ResolveEndpointFailedException; import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.impl.FooBar; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.support.DefaultExchange; @@ -63,10 +62,7 @@ public class CamelPostProcessorHelperTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setLocation("ref:myProp"); - + context.getPropertiesComponent().setLocation("ref:myProp"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/PropertiesAvailableEverywhereTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/PropertiesAvailableEverywhereTest.java index 8293005..1877a55 100644 --- a/core/camel-core/src/test/java/org/apache/camel/issues/PropertiesAvailableEverywhereTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/issues/PropertiesAvailableEverywhereTest.java @@ -34,9 +34,7 @@ public class PropertiesAvailableEverywhereTest extends ContextTestSupport { properties.put("foo", "bar"); camelContext.getRegistry().bind("myProp", properties); - - PropertiesComponent pc = camelContext.getComponent("properties", PropertiesComponent.class); - pc.addLocation("ref:myProp"); + camelContext.getPropertiesComponent().addLocation("ref:myProp"); return camelContext; } diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/TransactedPropertyPlaceholderIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/TransactedPropertyPlaceholderIssueTest.java index 8006426..67eee94 100644 --- a/core/camel-core/src/test/java/org/apache/camel/issues/TransactedPropertyPlaceholderIssueTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/issues/TransactedPropertyPlaceholderIssueTest.java @@ -52,11 +52,7 @@ public class TransactedPropertyPlaceholderIssueTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterPropertyPlaceholderTest.java b/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterPropertyPlaceholderTest.java index 39a2714..c6eb55c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterPropertyPlaceholderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterPropertyPlaceholderTest.java @@ -21,7 +21,6 @@ import java.util.Properties; import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.impl.JndiRegistry; import org.junit.Test; @@ -54,10 +53,7 @@ public class BeanLanguageOGNLWithDotInParameterPropertyPlaceholderTest extends C @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); - pc.setLocation("ref:myprop"); - + context.getPropertiesComponent().setLocation("ref:myprop"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/language/PropertyInjectAnnotationParameterTest.java b/core/camel-core/src/test/java/org/apache/camel/language/PropertyInjectAnnotationParameterTest.java index a1f7aa4..dc631e7 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/PropertyInjectAnnotationParameterTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/PropertyInjectAnnotationParameterTest.java @@ -22,7 +22,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; import org.apache.camel.PropertyInject; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.properties.PropertiesComponent; +import org.apache.camel.spi.PropertiesComponent; import org.junit.Test; /** @@ -61,12 +61,11 @@ public class PropertyInjectAnnotationParameterTest extends ContextTestSupport { protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent pc = new PropertiesComponent(); + PropertiesComponent pc = context.getPropertiesComponent(); Properties props = new Properties(); props.put("greeting", "Hello"); props.put("times", "3"); pc.setInitialProperties(props); - context.addComponent("properties", pc); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimplePropertiesNestedTest.java b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimplePropertiesNestedTest.java index 3a3d427..aeb9cb8 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimplePropertiesNestedTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimplePropertiesNestedTest.java @@ -53,11 +53,7 @@ public class SimplePropertiesNestedTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocations(new String[] {"org/apache/camel/component/properties/bar.properties"}); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("org/apache/camel/component/properties/bar.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWithPropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWithPropertiesTest.java index 712f6cf..262df63 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWithPropertiesTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWithPropertiesTest.java @@ -19,7 +19,6 @@ package org.apache.camel.language.simple; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.builder.SimpleBuilder; -import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.DefaultExchange; import org.junit.Assert; @@ -39,9 +38,7 @@ public class SimpleWithPropertiesTest { @Test public void testProperty() throws Exception { System.setProperty("test", "testValue"); - PropertiesComponent pc = new PropertiesComponent(); CamelContext context = new DefaultCamelContext(); - context.addComponent("properties", pc); // try to setup the property Exchange exchange = new DefaultExchange(context); diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/RouteAutoStartupTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/RouteAutoStartupTest.java index b9b7cf3..b9a9790 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/RouteAutoStartupTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/RouteAutoStartupTest.java @@ -126,10 +126,7 @@ public class RouteAutoStartupTest extends ContextTestSupport { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { - - PropertiesComponent properties = new PropertiesComponent(); - properties.setLocation("classpath:org/apache/camel/processor/routeAutoStartupTest.properties"); - context.addComponent("properties", properties); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/processor/routeAutoStartupTest.properties"); from("direct:start").autoStartup("{{autoStartupProp}}").to("mock:result"); } @@ -149,10 +146,7 @@ public class RouteAutoStartupTest extends ContextTestSupport { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { - - PropertiesComponent properties = new PropertiesComponent(); - properties.setLocation("classpath:org/apache/camel/processor/routeAutoStartupTest.properties"); - context.addComponent("properties", properties); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/processor/routeAutoStartupTest.properties"); from("direct:start").id("route1").autoStartup("{{noAutoStartupProp}}").to("mock:result"); } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java index 80c992b..768907d 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java @@ -22,7 +22,6 @@ import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.properties.PropertiesComponent; import org.junit.Test; public class SimpleMockPlaceholderTest extends ContextTestSupport { @@ -35,9 +34,7 @@ public class SimpleMockPlaceholderTest extends ContextTestSupport { myProp.put("foo", "log:foo"); myProp.put("end", "result"); - PropertiesComponent pc = new PropertiesComponent(); - pc.setInitialProperties(myProp); - context.addComponent("properties", pc); + context.getPropertiesComponent().setInitialProperties(myProp); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java index 8c03377..a1be5f2 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromPropertyPlaceholderTest.java @@ -52,11 +52,7 @@ public class InterceptFromPropertyPlaceholderTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("classpath:org/apache/camel/processor/intercept/myproperties.properties"); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/processor/intercept/myproperties.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/support/jsse/AbstractJsseParametersTest.java b/core/camel-core/src/test/java/org/apache/camel/support/jsse/AbstractJsseParametersTest.java index 116dfc7..8354462e 100644 --- a/core/camel-core/src/test/java/org/apache/camel/support/jsse/AbstractJsseParametersTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/support/jsse/AbstractJsseParametersTest.java @@ -24,7 +24,6 @@ import java.security.SecureRandom; import java.util.HashSet; import java.util.Properties; import java.util.Set; - import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; @@ -32,7 +31,6 @@ import javax.net.ssl.TrustManagerFactory; import org.apache.camel.CamelContext; import org.apache.camel.TestSupport; -import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.impl.DefaultCamelContext; public abstract class AbstractJsseParametersTest extends TestSupport { @@ -105,12 +103,8 @@ public abstract class AbstractJsseParametersTest extends TestSupport { properties.store(new FileOutputStream("target/jsse-test.properties"), "Generated by " + AbstractJsseParametersTest.class.getName()); - PropertiesComponent pc = new PropertiesComponent(); - pc.setLocation("file:./target/jsse-test.properties"); - CamelContext context = new DefaultCamelContext(); - context.addComponent("properties", pc); - + context.getPropertiesComponent().setLocation("file:./target/jsse-test.properties"); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlChoiceFilterRoutePropertyPlaceholderTest.java b/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlChoiceFilterRoutePropertyPlaceholderTest.java index f0e4b56..bc9dd0f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlChoiceFilterRoutePropertyPlaceholderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlChoiceFilterRoutePropertyPlaceholderTest.java @@ -63,8 +63,7 @@ public class DumpModelAsXmlChoiceFilterRoutePropertyPlaceholderTest extends Cont prop.put("extra", "extra-gold"); prop.put("mypath", "xpath"); - PropertiesComponent pc = context.getPropertiesComponent(true); - pc.setInitialProperties(prop); + context.getPropertiesComponent().setInitialProperties(prop); from("direct:start").routeId("myRoute").to("log:input").transform().header("{{duke}}").choice().when().header("{{best}}").to("mock:gold").filter() .header("{{extra}}").to("mock:extra-gold").endChoice().when().simple("${body} contains 'Camel'").to("mock:camel").otherwise().to("mock:other").end() diff --git a/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlPlaceholdersTest.java b/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlPlaceholdersTest.java index 75ab4ca..fe61ca1 100644 --- a/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlPlaceholdersTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlPlaceholdersTest.java @@ -50,9 +50,7 @@ public class DumpModelAsXmlPlaceholdersTest extends ContextTestSupport { @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - PropertiesComponent component = new PropertiesComponent(); - component.setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); - context.addComponent("properties", component); + context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/cheese.properties"); return context; } 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 5cfed94..db8b473 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 @@ -784,11 +784,8 @@ public final class IntrospectionSupport { static boolean isPropertyPlaceholder(CamelContext context, Object value) { if (context != null) { - PropertiesComponent pc = context.getPropertiesComponent(false); - if (pc != null) { - String text = value.toString(); - return text.contains(PropertiesComponent.PREFIX_TOKEN) && text.contains(PropertiesComponent.SUFFIX_TOKEN); - } + 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 cd9d93e..6efc2e9 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 @@ -1310,35 +1310,6 @@ public class ExpressionBuilder { return constantExpression(str); } - public static Expression propertiesComponentExpression(final String key, final String defaultValue) { - return new ExpressionAdapter() { - public Object evaluate(Exchange exchange) { - String text = simpleExpression(key).evaluate(exchange, String.class); - try { - // the properties component is mandatory if no locations provided - PropertiesComponent pc = exchange.getContext().getPropertiesComponent(false); - if (pc == null) { - throw new IllegalArgumentException("PropertiesComponent with name properties must be defined" - + " 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(PropertiesComponent.PREFIX_TOKEN + text + PropertiesComponent.SUFFIX_TOKEN); - } catch (Exception e) { - // property with key not found, use default value if provided - if (defaultValue != null) { - return defaultValue; - } - throw RuntimeCamelException.wrapRuntimeCamelException(e); - } - } - - @Override - public String toString() { - return "properties(" + key + ")"; - } - }; - } - /** * Returns an {@link TokenPairExpressionIterator} expression */
