You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/08/12 09:57:29 UTC

[camel] branch master updated (8745711 -> 8b25edf)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 8745711  CAMEL-13798: additional title fixes
     new daf9d25  CAMEL-13854: camel-microprofile-config: service file point to the wrong class
     new 43643fd  CAMEL-13855: camel-microprofile-config: discover properties sources from registry
     new 91c40c9  CAMEL-13856: camel-microprofile-config: sould have an option to enable/disable automatic lookup of properties sources
     new e2564f3  CAMEL-13857: camel-microprofile-config: should implement LoadablePropertiesSource
     new 43389ad  CAMEL-13858: camel-properties: load properties should iterate through loadable property source in reverse order
     new 08c6192  CAMEL-13859: came-properties: allow to filter properties by key when loading all
     new 8b25edf  CAMEL-13860: camel-properties: get[Inital|Override]Properties should never return null

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 components/camel-microprofile-config/pom.xml       |   5 +
 .../config/CamelMicroProfilePropertiesSource.java  |  49 ++++++-
 .../org/apache/camel/properties-source-factory     |   2 +-
 .../CamelMicroProfilePropertiesSourceTest.java     |  47 +++++--
 .../src/main/docs/properties-component.adoc        |   3 +-
 .../AbstractLocationPropertiesSource.java          |  14 ++
 .../component/properties/PropertiesComponent.java  | 116 ++++++++++++++---
 .../apache/camel/spi/LoadablePropertiesSource.java |   9 ++
 .../org/apache/camel/spi/PropertiesComponent.java  |  16 ++-
 .../PropertiesComponentPropertiesSourceTest.java   | 145 +++++++++++++++++++++
 .../PropertiesComponentConfiguration.java          |  14 ++
 11 files changed, 384 insertions(+), 36 deletions(-)
 create mode 100644 core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentPropertiesSourceTest.java


[camel] 04/07: CAMEL-13857: camel-microprofile-config: should implement LoadablePropertiesSource

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e2564f391d9bf40f028e176871827eccc2567925
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Aug 12 07:15:58 2019 +0200

    CAMEL-13857: camel-microprofile-config: should implement LoadablePropertiesSource
---
 components/camel-microprofile-config/pom.xml       |  5 ++++
 .../config/CamelMicroProfilePropertiesSource.java  | 31 +++++++++++++++++-----
 .../CamelMicroProfilePropertiesSourceTest.java     | 12 +++++++++
 3 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/components/camel-microprofile-config/pom.xml b/components/camel-microprofile-config/pom.xml
index f939abc..50eaa70 100644
--- a/components/camel-microprofile-config/pom.xml
+++ b/components/camel-microprofile-config/pom.xml
@@ -73,6 +73,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-api</artifactId>
             <scope>test</scope>
diff --git a/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java b/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
index 9c6b21c..a4e0524 100644
--- a/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
+++ b/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
@@ -16,9 +16,9 @@
  */
 package org.apache.camel.component.microprofile.config;
 
-import java.util.Optional;
+import java.util.Properties;
 
-import org.apache.camel.spi.PropertiesSource;
+import org.apache.camel.spi.LoadablePropertiesSource;
 import org.apache.camel.support.service.ServiceSupport;
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.ConfigProvider;
@@ -27,7 +27,7 @@ import org.eclipse.microprofile.config.ConfigProvider;
  * The microprofile-config component is used for bridging the Eclipse MicroProfile Config with Camels
  * properties component. This allows to use configuration management from Eclipse MicroProfile with Camel.
  */
-public class CamelMicroProfilePropertiesSource extends ServiceSupport implements PropertiesSource {
+public class CamelMicroProfilePropertiesSource extends ServiceSupport implements LoadablePropertiesSource {
 
     private Config config;
 
@@ -41,16 +41,35 @@ public class CamelMicroProfilePropertiesSource extends ServiceSupport implements
         if (config == null) {
             config = ConfigProvider.getConfig();
         }
-        Optional<String> value = config.getOptionalValue(name, String.class);
-        return value.orElse(null);
+        return config.getOptionalValue(name, String.class).orElse(null);
     }
 
     @Override
-    protected void doStart() throws Exception {
+    public Properties loadProperties() {
+        if (config == null) {
+            config = ConfigProvider.getConfig();
+        }
+
+        Properties answer = new Properties();
+
+        for (String key: config.getPropertyNames()) {
+            answer.put(key, config.getValue(key, String.class));
+        }
+
+        return answer;
+    }
+
+    @Override
+    protected void doInit() throws Exception {
         config = ConfigProvider.getConfig();
     }
 
     @Override
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    @Override
     protected void doStop() throws Exception {
         // noop
     }
diff --git a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
index 16370bc..3ac6ff2 100644
--- a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
+++ b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
@@ -23,9 +23,11 @@ import io.smallrye.config.SmallRyeConfigBuilder;
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.PropertiesSource;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.assertj.core.api.Assertions;
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
 import org.junit.Test;
@@ -68,6 +70,16 @@ public class CamelMicroProfilePropertiesSourceTest extends CamelTestSupport {
     }
 
     @Test
+    public void testLoadAll() throws Exception {
+        PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+        Properties properties = pc.loadProperties();
+
+        Assertions.assertThat(properties.get("start")).isEqualTo("direct:start");
+        Assertions.assertThat(properties.get("hi")).isEqualTo("World");
+        Assertions.assertThat(properties.get("my-mock")).isEqualTo("result");
+    }
+
+    @Test
     public void testMicroProfileConfig() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World from Camel");
 


[camel] 06/07: CAMEL-13859: came-properties: allow to filter properties by key when loading all

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 08c61928e278c42c35b537b3a1b985b7827566fd
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Aug 12 10:14:02 2019 +0200

    CAMEL-13859: came-properties: allow to filter properties by key when loading all
---
 .../config/CamelMicroProfilePropertiesSource.java  | 18 +++++++++
 .../AbstractLocationPropertiesSource.java          | 14 +++++++
 .../component/properties/PropertiesComponent.java  | 43 ++++++++++++++++++++++
 .../apache/camel/spi/LoadablePropertiesSource.java |  9 +++++
 .../org/apache/camel/spi/PropertiesComponent.java  | 16 +++++++-
 .../PropertiesComponentPropertiesSourceTest.java   | 36 ++++++++++++++++++
 6 files changed, 135 insertions(+), 1 deletion(-)

diff --git a/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java b/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
index a4e0524..88624e6 100644
--- a/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
+++ b/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.microprofile.config;
 
 import java.util.Properties;
+import java.util.function.Predicate;
 
 import org.apache.camel.spi.LoadablePropertiesSource;
 import org.apache.camel.support.service.ServiceSupport;
@@ -60,6 +61,23 @@ public class CamelMicroProfilePropertiesSource extends ServiceSupport implements
     }
 
     @Override
+    public Properties loadProperties(Predicate<String> filter) {
+        if (config == null) {
+            config = ConfigProvider.getConfig();
+        }
+
+        Properties answer = new Properties();
+
+        for (String name: answer.stringPropertyNames()) {
+            if (filter.test(name)) {
+                config.getOptionalValue(name, String.class).ifPresent(v -> answer.put(name, v));
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
     protected void doInit() throws Exception {
         config = ConfigProvider.getConfig();
     }
diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java
index 4a42e54..a019ac9 100644
--- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java
+++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/AbstractLocationPropertiesSource.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.properties;
 
 import java.util.Map;
 import java.util.Properties;
+import java.util.function.Predicate;
 
 import org.apache.camel.spi.LoadablePropertiesSource;
 import org.apache.camel.support.service.ServiceSupport;
@@ -50,6 +51,19 @@ public abstract class AbstractLocationPropertiesSource extends ServiceSupport im
     }
 
     @Override
+    public Properties loadProperties(Predicate<String> filter) {
+        Properties answer = new Properties();
+
+        for (String name: answer.stringPropertyNames()) {
+            if (filter.test(name)) {
+                answer.put(name, properties.get(name));
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
     public String getProperty(String name) {
         return properties.getProperty(name);
     }
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 10fd38c..29845c6 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
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 import org.apache.camel.CamelContextAware;
@@ -179,6 +180,9 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
 
     @Override
     public Properties loadProperties() {
+        // this method may be replaced by loadProperties(k -> true) but the underlying sources
+        // may have some optimization for bulk load so let's keep it
+
         Properties prop = new OrderedProperties();
 
         // use initial properties
@@ -212,6 +216,45 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
         return prop;
     }
 
+    @Override
+    public Properties loadProperties(Predicate<String> filter) {
+        Properties prop = new OrderedProperties();
+
+        // use initial properties
+        if (initialProperties != null) {
+            for (String name: initialProperties.stringPropertyNames()) {
+                if (filter.test(name)) {
+                    prop.put(name, initialProperties.get(name));
+                }
+            }
+        }
+
+        if (!sources.isEmpty()) {
+            // sources are ordered according to {@link org.apache.camel.support.OrderComparator} so
+            // it is needed to iterate them in reverse order otherwise lower priority sources may
+            // override properties from higher priority ones
+            for (int i = sources.size(); i-- > 0; ) {
+                PropertiesSource ps = sources.get(i);
+                if (ps instanceof LoadablePropertiesSource) {
+                    LoadablePropertiesSource lps = (LoadablePropertiesSource) ps;
+                    Properties p = lps.loadProperties(filter);
+                    prop.putAll(p);
+                }
+            }
+        }
+
+        // use override properties
+        if (overrideProperties != null) {
+            for (String name: overrideProperties.stringPropertyNames()) {
+                if (filter.test(name)) {
+                    prop.put(name, overrideProperties.get(name));
+                }
+            }
+        }
+
+        return prop;
+    }
+
     protected String parseUri(String uri, PropertiesLookup properties) {
         // enclose tokens if missing
         if (!uri.contains(PREFIX_TOKEN) && !uri.startsWith(PREFIX_TOKEN)) {
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/LoadablePropertiesSource.java b/core/camel-api/src/main/java/org/apache/camel/spi/LoadablePropertiesSource.java
index 32bf08f..90ab31d 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/LoadablePropertiesSource.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/LoadablePropertiesSource.java
@@ -17,6 +17,7 @@
 package org.apache.camel.spi;
 
 import java.util.Properties;
+import java.util.function.Predicate;
 
 import org.apache.camel.Ordered;
 
@@ -35,4 +36,12 @@ public interface LoadablePropertiesSource extends PropertiesSource {
      * @return the loaded properties
      */
     Properties loadProperties();
+
+    /**
+     * Loads the properties from the source filtering them out according to a predicate.
+     *
+     * @param filter the predicate used to filter out properties based on the key.
+     * @return the properties loaded.
+     */
+    Properties loadProperties(Predicate<String> filter);
 }
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 b063778..d92ed2a 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
@@ -19,6 +19,7 @@ package org.apache.camel.spi;
 import java.util.List;
 import java.util.Optional;
 import java.util.Properties;
+import java.util.function.Predicate;
 
 import org.apache.camel.Component;
 import org.apache.camel.StaticService;
@@ -62,13 +63,26 @@ public interface PropertiesComponent extends Component, StaticService {
     Optional<String> resolveProperty(String key);
 
     /**
-     * Loads the properties from the default locations.
+     * Loads the properties from the default locations and sources.
      *
      * @return the properties loaded.
      */
     Properties loadProperties();
 
     /**
+     * Loads the properties from the default locations and sources filtering them out according to a predicate.
+     * </p>
+     * <pre>{@code
+     *     PropertiesComponent pc = getPropertiesComponent();
+     *     Properties props = pc.loadProperties(key -> key.startsWith("camel.component.seda"));
+     * }</pre>
+     *
+     * @param filter the predicate used to filter out properties based on the key.
+     * @return the properties loaded.
+     */
+    Properties loadProperties(Predicate<String> filter);
+
+    /**
      * Gets the configured properties locations.
      * This may be empty if the properties component has only been configured with {@link PropertiesSource}.
      */
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 38b7714..2807827 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
@@ -17,6 +17,7 @@
 package org.apache.camel.component.properties;
 
 import java.util.Properties;
+import java.util.function.Predicate;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Ordered;
@@ -53,6 +54,27 @@ public class PropertiesComponentPropertiesSourceTest {
     }
 
     @Test
+    public void testFilteredPropertiesSources() {
+        Properties initial = new Properties();
+        initial.put("initial-1", "initial-val-1");
+        initial.put("initial-2", "initial-val-2");
+        initial.put("my-key-2", "initial-val-2");
+
+        CamelContext context = new DefaultCamelContext();
+        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);
+
+        Properties properties = pc.loadProperties(k -> k.endsWith("-2"));
+
+        assertThat(properties).hasSize(2);
+        assertThat(properties.get("initial-2")).isEqualTo("initial-val-2");
+        assertThat(properties.get("my-key-2")).isEqualTo("my-val-2");
+    }
+
+    @Test
     public void testDisablePropertiesSourceDiscovery() {
         PropertiesComponent pc = new PropertiesComponent();
         pc.setAutoDiscoverPropertiesSources(false);
@@ -71,6 +93,7 @@ public class PropertiesComponentPropertiesSourceTest {
             .hasMessage("Property with key [my-key-2] not found in properties from text: {{my-key-2}}");
     }
 
+
     private static final class PropertiesPropertiesSource extends Properties implements LoadablePropertiesSource, Ordered {
         private final String name;
         private final int order;
@@ -104,6 +127,19 @@ public class PropertiesComponentPropertiesSourceTest {
         public Properties loadProperties() {
             return this;
         }
+
+        @Override
+        public Properties loadProperties(Predicate<String> filter) {
+            Properties props = new Properties();
+
+            for (String name: stringPropertyNames()) {
+                if (filter.test(name)) {
+                    props.put(name, get(name));
+                }
+            }
+
+            return props;
+        }
     }
 }
 


[camel] 07/07: CAMEL-13860: camel-properties: get[Inital|Override]Properties should never return null

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8b25edf7dc960f9323c63bc2d6e04137706ac810
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Aug 12 10:49:52 2019 +0200

    CAMEL-13860: camel-properties: get[Inital|Override]Properties should never return null
---
 .../camel/component/properties/PropertiesComponent.java   | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

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 29845c6..22366f9 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
@@ -401,7 +401,14 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
         this.ignoreMissingLocation = ignoreMissingLocation;
     }
 
+    /**
+     * @return a list of properties which will be used before any locations are resolved (can't be null).
+     */
     public Properties getInitialProperties() {
+        if (initialProperties == null) {
+            initialProperties = new Properties();
+        }
+
         return initialProperties;
     }
 
@@ -413,7 +420,14 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
         this.initialProperties = initialProperties;
     }
 
+    /**
+     * @return a list of properties that take precedence and will use first, if a property exist (can't be null).
+     */
     public Properties getOverrideProperties() {
+        if (overrideProperties == null) {
+            overrideProperties = new Properties();
+        }
+
         return overrideProperties;
     }
 
@@ -488,6 +502,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
     public void setEnvironmentVariableMode(int environmentVariableMode) {
         this.environmentVariableMode = environmentVariableMode;
     }
+
     public boolean isAutoDiscoverPropertiesSources() {
         return autoDiscoverPropertiesSources;
     }


[camel] 01/07: CAMEL-13854: camel-microprofile-config: service file point to the wrong class

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit daf9d25cd29f1302333e1fe5b7f73f21fb26dd6d
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sun Aug 11 23:24:20 2019 +0200

    CAMEL-13854: camel-microprofile-config: service file point to the wrong class
---
 .../services/org/apache/camel/properties-source-factory       |  2 +-
 .../config/CamelMicroProfilePropertiesSourceTest.java         | 11 +++--------
 .../camel/component/properties/PropertiesComponent.java       |  2 +-
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/components/camel-microprofile-config/src/main/resources/META-INF/services/org/apache/camel/properties-source-factory b/components/camel-microprofile-config/src/main/resources/META-INF/services/org/apache/camel/properties-source-factory
index 74bd136..0e0b1a7 100644
--- a/components/camel-microprofile-config/src/main/resources/META-INF/services/org/apache/camel/properties-source-factory
+++ b/components/camel-microprofile-config/src/main/resources/META-INF/services/org/apache/camel/properties-source-factory
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-class=org.apache.camel.component.microprofile.config.CamelMicroProfileConfigSource
+class=org.apache.camel.component.microprofile.config.CamelMicroProfilePropertiesSource
diff --git a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
index 8ede269..1487926 100644
--- a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
+++ b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
@@ -23,7 +23,6 @@ import io.smallrye.config.SmallRyeConfigBuilder;
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
@@ -40,16 +39,12 @@ public class CamelMicroProfilePropertiesSourceTest extends CamelTestSupport {
         prop.put("my-mock", "result");
 
         // create PMC config source and register it so we can use it for testing
-        PropertiesConfigSource pcs = new PropertiesConfigSource(prop, "my-smallrye-config");
+        final PropertiesConfigSource pcs = new PropertiesConfigSource(prop, "my-smallrye-config");
         final Config config = new SmallRyeConfigBuilder().withSources(pcs).build();
+
         ConfigProviderResolver.instance().registerConfig(config, CamelMicroProfilePropertiesSourceTest.class.getClassLoader());
 
-        // should auto-detect this JAR on the classpath and use it (but this can only be tested outside this component)
-        CamelContext context = super.createCamelContext();
-        // ... so we add the source manually
-        PropertiesComponent pc = (PropertiesComponent) context.getPropertiesComponent();
-        pc.addPropertiesSource(new CamelMicroProfilePropertiesSource());
-        return context;
+        return super.createCamelContext();
     }
 
     @Test
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 a97f446..17db6ba 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
@@ -461,7 +461,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
 
         // discover any 3rd party properties sources
         try {
-            FactoryFinder factoryFinder = getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder("META-INF/services/org/apache/camel");
+            FactoryFinder factoryFinder = getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder("META-INF/services/org/apache/camel/");
             Class<?> type = factoryFinder.findClass("properties-source-factory").orElse(null);
             if (type != null) {
                 Object obj = getCamelContext().getInjector().newInstance(type, false);


[camel] 03/07: CAMEL-13856: camel-microprofile-config: sould have an option to enable/disable automatic lookup of properties sources

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 91c40c941d706f06aeac27fb685205c7900ec8c1
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Aug 12 06:54:08 2019 +0200

    CAMEL-13856: camel-microprofile-config: sould have an option to enable/disable automatic lookup of properties sources
---
 .../src/main/docs/properties-component.adoc        |  3 +-
 .../component/properties/PropertiesComponent.java  | 55 ++++++++++++++--------
 .../PropertiesComponentPropertiesSourceTest.java   | 33 +++++++++++--
 .../PropertiesComponentConfiguration.java          | 14 ++++++
 4 files changed, 79 insertions(+), 26 deletions(-)

diff --git a/components/camel-properties/src/main/docs/properties-component.adoc b/components/camel-properties/src/main/docs/properties-component.adoc
index 71bdf2e..83dbb0a 100644
--- a/components/camel-properties/src/main/docs/properties-component.adoc
+++ b/components/camel-properties/src/main/docs/properties-component.adoc
@@ -15,7 +15,7 @@ Where *key* is the key for the property to lookup
 == Options
 
 // component options: START
-The Properties component supports 12 options, which are listed below.
+The Properties component supports 13 options, which are listed below.
 
 
 
@@ -32,6 +32,7 @@ The Properties component supports 12 options, which are listed below.
 | *overrideProperties* (advanced) | Sets a special list of override properties that take precedence and will use first, if a property exist. |  | Properties
 | *systemPropertiesMode* (common) | Sets the JVM system property mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use system properties if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode | 2 | int
 | *environmentVariableMode* (common) | Sets the OS environment variables mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use OS environment variables if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode | 2 | int
+| *autoDiscoverProperties Sources* (common) | Whether to automatically discovery instances of PropertiesSource from registry and service factory. | true | boolean
 | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
 | *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 |===
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 42ba34c..260309d 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
@@ -122,6 +122,9 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
     private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_OVERRIDE;
     @Metadata(defaultValue = "" + ENVIRONMENT_VARIABLES_MODE_OVERRIDE, enums = "0,1,2")
     private int environmentVariableMode = ENVIRONMENT_VARIABLES_MODE_OVERRIDE;
+    @Metadata(defaultValue = "true")
+    private boolean autoDiscoverPropertiesSources = true;
+
 
     public PropertiesComponent() {
         super();
@@ -438,6 +441,16 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
     public void setEnvironmentVariableMode(int environmentVariableMode) {
         this.environmentVariableMode = environmentVariableMode;
     }
+    public boolean isAutoDiscoverPropertiesSources() {
+        return autoDiscoverPropertiesSources;
+    }
+
+    /**
+     * Whether to automatically discovery instances of {@link PropertiesSource} from registry and service factory.
+     */
+    public void setAutoDiscoverPropertiesSources(boolean autoDiscoverPropertiesSources) {
+        this.autoDiscoverPropertiesSources = autoDiscoverPropertiesSources;
+    }
 
     @Override
     public void addPropertiesSource(PropertiesSource propertiesSource) {
@@ -459,29 +472,31 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
     protected void doInit() throws Exception {
         super.doInit();
 
-        // discover any 3rd party properties sources
-        try {
-            for (PropertiesSource source: getCamelContext().getRegistry().findByType(PropertiesSource.class)) {
-                addPropertiesSource(source);
-                LOG.info("PropertiesComponent added custom PropertiesSource (registry): {}", source);
-            }
+        if (isAutoDiscoverPropertiesSources()) {
+            // discover any 3rd party properties sources
+            try {
+                for (PropertiesSource source : getCamelContext().getRegistry().findByType(PropertiesSource.class)) {
+                    addPropertiesSource(source);
+                    LOG.info("PropertiesComponent added custom PropertiesSource (registry): {}", source);
+                }
 
-            FactoryFinder factoryFinder = getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder("META-INF/services/org/apache/camel/");
-            Class<?> type = factoryFinder.findClass("properties-source-factory").orElse(null);
-            if (type != null) {
-                Object obj = getCamelContext().getInjector().newInstance(type, false);
-                if (obj instanceof PropertiesSource) {
-                    PropertiesSource ps = (PropertiesSource) obj;
-                    addPropertiesSource(ps);
-                    LOG.info("PropertiesComponent added custom PropertiesSource (factory): {}", ps);
-                } else if (obj != null) {
-                    LOG.warn("PropertiesComponent cannot add custom PropertiesSource as the type is not a org.apache.camel.component.properties.PropertiesSource but: " + type.getName());
+                FactoryFinder factoryFinder = getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder("META-INF/services/org/apache/camel/");
+                Class<?> type = factoryFinder.findClass("properties-source-factory").orElse(null);
+                if (type != null) {
+                    Object obj = getCamelContext().getInjector().newInstance(type, false);
+                    if (obj instanceof PropertiesSource) {
+                        PropertiesSource ps = (PropertiesSource) obj;
+                        addPropertiesSource(ps);
+                        LOG.info("PropertiesComponent added custom PropertiesSource (factory): {}", ps);
+                    } else if (obj != null) {
+                        LOG.warn("PropertiesComponent cannot add custom PropertiesSource as the type is not a org.apache.camel.component.properties.PropertiesSource but: " + type.getName());
+                    }
                 }
+            } catch (NoFactoryAvailableException e) {
+                // ignore
+            } catch (Exception e) {
+                LOG.debug("Error discovering and using custom PropertiesSource due to " + e.getMessage() + ". This exception is ignored", e);
             }
-        } catch (NoFactoryAvailableException e) {
-            // ignore
-        } catch (Exception e) {
-            LOG.debug("Error discovering and using custom PropertiesSource due to " + e.getMessage() + ". This exception is ignored", e);
         }
 
         ServiceHelper.initService(sources);
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 77aa267..4ddb75b 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
@@ -18,19 +18,42 @@ package org.apache.camel.component.properties;
 
 import java.util.Properties;
 
-import org.apache.camel.ContextTestSupport;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.spi.PropertiesSource;
 import org.junit.Test;
 
-public class PropertiesComponentPropertiesSourceTest extends ContextTestSupport {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class PropertiesComponentPropertiesSourceTest {
     @Test
     public void testPropertiesSourceFromRegistry() {
+        CamelContext context = new DefaultCamelContext();
         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"));
-        context.start();
 
-        assertEquals("my-val-1", context.resolvePropertyPlaceholders("{{my-key-1}}"));
-        assertEquals("my-val-2", context.resolvePropertyPlaceholders("{{my-key-2}}"));
+        assertThat(context.resolvePropertyPlaceholders("{{my-key-1}}")).isEqualTo("my-val-1");
+        assertThat(context.resolvePropertyPlaceholders("{{my-key-2}}")).isEqualTo("my-val-2");
+    }
+
+    @Test
+    public void testDisablePropertiesSourceDiscovery() {
+        PropertiesComponent pc = new PropertiesComponent();
+        pc.setAutoDiscoverPropertiesSources(false);
+
+        CamelContext context = new DefaultCamelContext();
+        context.addComponent("properties", pc);
+        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"));
+
+        assertThatThrownBy(() -> context.resolvePropertyPlaceholders("{{my-key-1}}"))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Property with key [my-key-1] not found in properties from text: {{my-key-1}}");
+
+        assertThatThrownBy(() -> context.resolvePropertyPlaceholders("{{my-key-2}}"))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("Property with key [my-key-2] not found in properties from text: {{my-key-2}}");
     }
 
     private static final class PropertiesPropertiesSource extends Properties implements PropertiesSource {
diff --git a/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java
index 2749c5c..2218e81 100644
--- a/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-properties-starter/src/main/java/org/apache/camel/component/properties/springboot/PropertiesComponentConfiguration.java
@@ -98,6 +98,11 @@ public class PropertiesComponentConfiguration
      */
     private Integer environmentVariableMode = 2;
     /**
+     * Whether to automatically discovery instances of PropertiesSource from
+     * registry and service factory.
+     */
+    private Boolean autoDiscoverPropertiesSources = true;
+    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
@@ -189,6 +194,15 @@ public class PropertiesComponentConfiguration
         this.environmentVariableMode = environmentVariableMode;
     }
 
+    public Boolean getAutoDiscoverPropertiesSources() {
+        return autoDiscoverPropertiesSources;
+    }
+
+    public void setAutoDiscoverPropertiesSources(
+            Boolean autoDiscoverPropertiesSources) {
+        this.autoDiscoverPropertiesSources = autoDiscoverPropertiesSources;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }


[camel] 02/07: CAMEL-13855: camel-microprofile-config: discover properties sources from registry

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 43643fd73dc9ecdcc25656648aa31f28ef3fce3a
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sun Aug 11 23:57:38 2019 +0200

    CAMEL-13855: camel-microprofile-config: discover properties sources from registry
---
 .../CamelMicroProfilePropertiesSourceTest.java     | 24 +++++++++-
 .../component/properties/PropertiesComponent.java  |  7 ++-
 .../PropertiesComponentPropertiesSourceTest.java   | 54 ++++++++++++++++++++++
 3 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
index 1487926..16370bc 100644
--- a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
+++ b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
@@ -23,6 +23,8 @@ import io.smallrye.config.SmallRyeConfigBuilder;
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.PropertiesSource;
+import org.apache.camel.spi.Registry;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
@@ -47,11 +49,29 @@ public class CamelMicroProfilePropertiesSourceTest extends CamelTestSupport {
         return super.createCamelContext();
     }
 
+    @Override
+    protected void bindToRegistry(Registry registry) throws Exception {
+        Properties prop = new Properties();
+        prop.put("who", "Camel");
+
+        registry.bind("ps", new PropertiesSource() {
+            @Override
+            public String getName() {
+                return "ps";
+            }
+
+            @Override
+            public String getProperty(String name) {
+                return prop.getProperty(name);
+            }
+        });
+    }
+
     @Test
     public void testMicroProfileConfig() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World from Camel");
 
-        template.sendBody("direct:start", context.resolvePropertyPlaceholders("Hello {{hi}}"));
+        template.sendBody("direct:start", context.resolvePropertyPlaceholders("Hello {{hi}} from {{who}}"));
 
         assertMockEndpointsSatisfied();
     }
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 17db6ba..42ba34c 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
@@ -461,6 +461,11 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
 
         // discover any 3rd party properties sources
         try {
+            for (PropertiesSource source: getCamelContext().getRegistry().findByType(PropertiesSource.class)) {
+                addPropertiesSource(source);
+                LOG.info("PropertiesComponent added custom PropertiesSource (registry): {}", source);
+            }
+
             FactoryFinder factoryFinder = getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder("META-INF/services/org/apache/camel/");
             Class<?> type = factoryFinder.findClass("properties-source-factory").orElse(null);
             if (type != null) {
@@ -468,7 +473,7 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
                 if (obj instanceof PropertiesSource) {
                     PropertiesSource ps = (PropertiesSource) obj;
                     addPropertiesSource(ps);
-                    LOG.info("PropertiesComponent added custom PropertiesSource: {}", ps);
+                    LOG.info("PropertiesComponent added custom PropertiesSource (factory): {}", ps);
                 } else if (obj != null) {
                     LOG.warn("PropertiesComponent cannot add custom PropertiesSource as the type is not a org.apache.camel.component.properties.PropertiesSource but: " + type.getName());
                 }
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
new file mode 100644
index 0000000..77aa267
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentPropertiesSourceTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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 java.util.Properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.spi.PropertiesSource;
+import org.junit.Test;
+
+public class PropertiesComponentPropertiesSourceTest extends ContextTestSupport {
+    @Test
+    public void testPropertiesSourceFromRegistry() {
+        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"));
+        context.start();
+
+        assertEquals("my-val-1", context.resolvePropertyPlaceholders("{{my-key-1}}"));
+        assertEquals("my-val-2", context.resolvePropertyPlaceholders("{{my-key-2}}"));
+    }
+
+    private static final class PropertiesPropertiesSource extends Properties implements PropertiesSource {
+        private final String name;
+
+        public PropertiesPropertiesSource(String name, String... kv) {
+            assert kv.length % 2 == 0;
+
+            this.name = name;
+
+            for (int i = 0; i < kv.length; i += 2) {
+                super.setProperty(kv[i], kv[i + 1]);
+            }
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+    }
+}


[camel] 05/07: CAMEL-13858: camel-properties: load properties should iterate through loadable property source in reverse order

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 43389ad12761a8ec1631cee00c1c87d538584df8
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Aug 12 07:35:56 2019 +0200

    CAMEL-13858: camel-properties: load properties should iterate through loadable property source in reverse order
---
 .../component/properties/PropertiesComponent.java  |  6 +++-
 .../PropertiesComponentPropertiesSourceTest.java   | 36 ++++++++++++++++++++--
 2 files changed, 39 insertions(+), 3 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 260309d..10fd38c 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
@@ -187,7 +187,11 @@ public class PropertiesComponent extends DefaultComponent implements org.apache.
         }
 
         if (!sources.isEmpty()) {
-            for (PropertiesSource ps : sources) {
+            // sources are ordered according to {@link org.apache.camel.support.OrderComparator} so
+            // it is needed to iterate them in reverse order otherwise lower priority sources may
+            // override properties from higher priority ones
+            for (int i = sources.size(); i-- > 0; ) {
+                PropertiesSource ps = sources.get(i);
                 if (ps instanceof LoadablePropertiesSource) {
                     LoadablePropertiesSource lps = (LoadablePropertiesSource) ps;
                     Properties p = lps.loadProperties();
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 4ddb75b..38b7714 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
@@ -19,8 +19,9 @@ package org.apache.camel.component.properties;
 import java.util.Properties;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Ordered;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.spi.PropertiesSource;
+import org.apache.camel.spi.LoadablePropertiesSource;
 import org.junit.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -38,6 +39,20 @@ public class PropertiesComponentPropertiesSourceTest {
     }
 
     @Test
+    public void testOrderedPropertiesSources() {
+        CamelContext context = new DefaultCamelContext();
+        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();
+
+        assertThat(properties.get("my-key-1")).isEqualTo("my-val-1");
+        assertThat(properties.get("my-key-2")).isEqualTo("my-val-2");
+        assertThat(properties.get("shared")).isEqualTo("v1");
+    }
+
+    @Test
     public void testDisablePropertiesSourceDiscovery() {
         PropertiesComponent pc = new PropertiesComponent();
         pc.setAutoDiscoverPropertiesSources(false);
@@ -56,13 +71,19 @@ public class PropertiesComponentPropertiesSourceTest {
             .hasMessage("Property with key [my-key-2] not found in properties from text: {{my-key-2}}");
     }
 
-    private static final class PropertiesPropertiesSource extends Properties implements PropertiesSource {
+    private static final class PropertiesPropertiesSource extends Properties implements LoadablePropertiesSource, Ordered {
         private final String name;
+        private final int order;
 
         public PropertiesPropertiesSource(String name, String... kv) {
+            this(Ordered.LOWEST, name, kv);
+        }
+
+        public PropertiesPropertiesSource(int order, String name, String... kv) {
             assert kv.length % 2 == 0;
 
             this.name = name;
+            this.order = order;
 
             for (int i = 0; i < kv.length; i += 2) {
                 super.setProperty(kv[i], kv[i + 1]);
@@ -73,5 +94,16 @@ public class PropertiesComponentPropertiesSourceTest {
         public String getName() {
             return name;
         }
+
+        @Override
+        public int getOrder() {
+            return order;
+        }
+
+        @Override
+        public Properties loadProperties() {
+            return this;
+        }
     }
 }
+