This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch properties in repository https://gitbox.apache.org/repos/asf/camel.git
commit 08121c16e66d7896e3bfc100d2991930d6ca9fec Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Jul 3 19:51:12 2019 +0200 CAMEL-13708: Properties component should have API to make it easier to lookup a property on-demand or from all pre-loaded properties. --- .../component/properties/DefaultPropertiesParser.java | 2 +- .../camel/component/properties/PropertiesComponent.java | 14 +++++++++++++- .../camel/component/properties/PropertiesLookup.java | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java index 659ebac..01aba6b 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java @@ -238,7 +238,7 @@ public class DefaultPropertiesParser implements PropertiesParser { if (value == null) { StringBuilder esb = new StringBuilder(); - if (propertiesComponent == null || propertiesComponent.getCamelContext().getGlobalOption(PropertiesComponent.DEFAULT_CREATED) != null) { + if (propertiesComponent == null || propertiesComponent.getCamelContext().getGlobalOption(PropertiesComponent.DEFAULT_CREATED) == null) { // if the component was auto created then include more information that the end user should define it esb.append("PropertiesComponent with name properties must be defined in CamelContext to support property placeholders. "); } 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 35debf7..b629d88 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 @@ -105,7 +105,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. private static final Logger LOG = LoggerFactory.getLogger(PropertiesComponent.class); private final Map<String, PropertiesFunction> functions = new LinkedHashMap<>(); - private PropertiesResolver propertiesResolver = new DefaultPropertiesResolver(this); + private PropertiesResolver propertiesResolver; private PropertiesParser propertiesParser = new DefaultPropertiesParser(this); private final PropertiesLookup propertiesLookup = new DefaultPropertiesLookup(this); private final List<PropertiesSource> sources = new ArrayList<>(); @@ -201,6 +201,14 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. } } + // use legacy properties resolver + if (propertiesResolver != null) { + Properties p = propertiesResolver.resolveProperties(getCamelContext(), ignoreMissingLocation, locations); + if (p != null && !p.isEmpty()) { + prop.putAll(p); + } + } + // use override properties if (overrideProperties != null) { // make a copy to avoid affecting the original properties @@ -514,6 +522,10 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. } else { sources.add(propertiesSource); } + if (isInit()) { + // if we are already initialized we need to init the properties source also + ServiceHelper.initService(propertiesSource); + } } public List<PropertiesSource> getSources() { diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesLookup.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesLookup.java index 19411c7..cc191c1 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesLookup.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesLookup.java @@ -19,6 +19,7 @@ package org.apache.camel.component.properties; /** * Used by {@link PropertiesParser} to lookup properties by their name */ +@FunctionalInterface public interface PropertiesLookup { /**