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 78760066c211d6e28c80cc9e93c6003f8c65c797 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Jul 3 06:31:19 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. --- components/camel-blueprint/pom.xml | 4 ++-- .../camel/blueprint/BlueprintPropertiesParser.java | 6 ++---- .../component/jasypt/JasyptPropertiesParser.java | 4 ++-- components/camel-spring-boot/pom.xml | 4 ++++ .../camel/spring/boot/SpringPropertiesParser.java | 5 ++--- components/camel-spring/pom.xml | 4 ++++ .../spi/BridgePropertyPlaceholderConfigurer.java | 24 ++++++++++++---------- .../endpoint/dsl/FtpEndpointBuilderFactory.java | 12 +++++------ .../endpoint/dsl/FtpsEndpointBuilderFactory.java | 12 +++++------ .../endpoint/dsl/SftpEndpointBuilderFactory.java | 12 +++++------ .../camel/example/cdi/cassandraql/Application.java | 4 ++-- .../camel/example/cdi/properties/Application.java | 4 ++-- 12 files changed, 51 insertions(+), 44 deletions(-) diff --git a/components/camel-blueprint/pom.xml b/components/camel-blueprint/pom.xml index cd197ec..d90d5bc 100644 --- a/components/camel-blueprint/pom.xml +++ b/components/camel-blueprint/pom.xml @@ -41,7 +41,7 @@ <dependencies> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-support</artifactId> + <artifactId>camel-core</artifactId> </dependency> <dependency> <groupId>org.apache.camel</groupId> @@ -53,7 +53,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> + <artifactId>camel-properties</artifactId> </dependency> <dependency> <groupId>org.osgi</groupId> diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java index 4ced68a..14ba14d 100644 --- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import org.apache.aries.blueprint.ExtendedBeanMetadata; @@ -30,6 +29,7 @@ import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder; import org.apache.aries.blueprint.ext.PropertyPlaceholder; import org.apache.camel.component.properties.DefaultPropertiesParser; import org.apache.camel.component.properties.PropertiesComponent; +import org.apache.camel.component.properties.PropertiesLookup; import org.apache.camel.component.properties.PropertiesParser; import org.apache.camel.support.ObjectHelper; import org.osgi.service.blueprint.container.BlueprintContainer; @@ -85,8 +85,6 @@ public class BlueprintPropertiesParser extends DefaultPropertiesParser { /** * Obtains a {@link Class} instance for "org.apache.aries.blueprint.ext.AbstractPropertyPlaceholderExt" - * @param clazz - * @return */ private Class<?> newPlaceholderClass(Class<?> clazz) { Class<?> c = clazz; @@ -146,7 +144,7 @@ public class BlueprintPropertiesParser extends DefaultPropertiesParser { } @Override - public String parseProperty(String key, String value, Properties properties) { + public String parseProperty(String key, String value, PropertiesLookup properties) { log.trace("Parsing property key: {} with value: {}", key, value); String answer = null; diff --git a/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java b/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java index eb832bb..f941206 100644 --- a/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java +++ b/components/camel-jasypt/src/main/java/org/apache/camel/component/jasypt/JasyptPropertiesParser.java @@ -16,13 +16,13 @@ */ package org.apache.camel.component.jasypt; -import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import static java.lang.String.format; import org.apache.camel.component.properties.DefaultPropertiesParser; +import org.apache.camel.component.properties.PropertiesLookup; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; import org.jasypt.encryption.StringEncryptor; @@ -50,7 +50,7 @@ public class JasyptPropertiesParser extends DefaultPropertiesParser { } @Override - public String parseProperty(String key, String value, Properties properties) { + public String parseProperty(String key, String value, PropertiesLookup properties) { log.trace(format("Parsing property '%s=%s'", key, value)); if (value != null) { initEncryptor(); diff --git a/components/camel-spring-boot/pom.xml b/components/camel-spring-boot/pom.xml index 3bd7b24..c318f53 100644 --- a/components/camel-spring-boot/pom.xml +++ b/components/camel-spring-boot/pom.xml @@ -77,6 +77,10 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-main</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-properties</artifactId> + </dependency> <!-- JMX is enabled by default --> <dependency> <groupId>org.apache.camel</groupId> diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringPropertiesParser.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringPropertiesParser.java index 8288b57..f917410 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringPropertiesParser.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringPropertiesParser.java @@ -16,9 +16,8 @@ */ package org.apache.camel.spring.boot; -import java.util.Properties; - import org.apache.camel.component.properties.DefaultPropertiesParser; +import org.apache.camel.component.properties.PropertiesLookup; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.PropertyResolver; @@ -32,7 +31,7 @@ class SpringPropertiesParser extends DefaultPropertiesParser { // Overridden @Override - public String parseProperty(String key, String value, Properties properties) { + public String parseProperty(String key, String value, PropertiesLookup properties) { return propertyResolver.getProperty(key); } diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml index 398d32c..d9efcae 100644 --- a/components/camel-spring/pom.xml +++ b/components/camel-spring/pom.xml @@ -40,6 +40,10 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-properties</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-main</artifactId> </dependency> <dependency> diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java index 84fbedb..e4d5666 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java @@ -22,7 +22,9 @@ import java.util.Properties; import org.apache.camel.CamelContext; import org.apache.camel.component.properties.AugmentedPropertyNameAwarePropertiesParser; +import org.apache.camel.component.properties.DefaultPropertiesLookup; import org.apache.camel.component.properties.PropertiesLocation; +import org.apache.camel.component.properties.PropertiesLookup; import org.apache.camel.component.properties.PropertiesParser; import org.apache.camel.component.properties.PropertiesResolver; import org.springframework.beans.BeansException; @@ -125,7 +127,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf String value = props.getProperty(placeholder); if (parser != null) { // Just apply the parser to the place holder value to avoid configuring the other placeholder configure twice for the inside and outside camel context - return parser.parseProperty(placeholder, value, props); + return parser.parseProperty(placeholder, value, new DefaultPropertiesLookup(props)); } else { return value; } @@ -155,7 +157,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, Properties properties, String prefixToken, String suffixToken, + public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException { // first let Camel parse the text as it may contain Camel placeholders @@ -177,7 +179,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, Properties properties, String prefixToken, String suffixToken) throws IllegalArgumentException { + public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken) throws IllegalArgumentException { String answer = parser.parseUri(text, properties, prefixToken, suffixToken); if (answer != null) { answer = springResolvePlaceholders(answer, properties); @@ -188,7 +190,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseProperty(String key, String value, Properties properties) { + public String parseProperty(String key, String value, PropertiesLookup properties) { String answer = parser.parseProperty(key, value, properties); if (answer != null) { answer = springResolvePlaceholders(answer, properties); @@ -205,7 +207,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf * @param properties the properties * @return the parsed text with replaced placeholders, or the original text as is */ - protected String springResolvePlaceholders(String text, Properties properties) { + protected String springResolvePlaceholders(String text, PropertiesLookup properties) { return helper.replacePlaceholders(text, new BridgePropertyPlaceholderResolver(properties)); } @@ -224,9 +226,9 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf private class BridgePropertyPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver { - private final Properties properties; + private final PropertiesLookup properties; - BridgePropertyPlaceholderResolver(Properties properties) { + BridgePropertyPlaceholderResolver(PropertiesLookup properties) { this.properties = properties; } @@ -236,7 +238,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf propVal = resolveSystemProperty(placeholderName); } if (propVal == null) { - propVal = properties.getProperty(placeholderName); + propVal = properties.lookup(placeholderName); } if (propVal == null && systemPropertiesMode == SYSTEM_PROPERTIES_MODE_FALLBACK) { propVal = resolveSystemProperty(placeholderName); @@ -256,7 +258,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, Properties properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, + public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException { String answer = null; if (delegate != null) { @@ -280,7 +282,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseUri(String text, Properties properties, String prefixToken, String suffixToken) throws IllegalArgumentException { + public String parseUri(String text, PropertiesLookup properties, String prefixToken, String suffixToken) throws IllegalArgumentException { String answer = null; if (delegate != null) { answer = delegate.parseUri(text, properties, prefixToken, suffixToken); @@ -292,7 +294,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override - public String parseProperty(String key, String value, Properties properties) { + public String parseProperty(String key, String value, PropertiesLookup properties) { String answer = null; if (delegate != null) { answer = delegate.parseProperty(key, value, properties); diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpEndpointBuilderFactory.java index f219346..89af936 100644 --- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpEndpointBuilderFactory.java @@ -956,12 +956,12 @@ public interface FtpEndpointBuilderFactory { * JDK IO API cannot always determine whether a file is currently being * used by another process. The option readLockCheckInterval can be used * to set the check frequency. fileLock - is for using - * java.nio.channels.FileLock. This option is not avail for the FTP - * component. This approach should be avoided when accessing a remote - * file system via a mount/share unless that file system supports - * distributed file locks. rename - rename is for using a try to rename - * the file as a test if we can get exclusive read-lock. idempotent - - * (only for file component) idempotent is for using a + * java.nio.channels.FileLock. This option is not avail for Windows OS + * and the FTP component. This approach should be avoided when accessing + * a remote file system via a mount/share unless that file system + * supports distributed file locks. rename - rename is for using a try + * to rename the file as a test if we can get exclusive read-lock. + * idempotent - (only for file component) idempotent is for using a * idempotentRepository as the read-lock. This allows to use read locks * that supports clustering if the idempotent repository implementation * supports that. idempotent-changed - (only for file component) diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpsEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpsEndpointBuilderFactory.java index 3145630..800bb9e 100644 --- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpsEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/FtpsEndpointBuilderFactory.java @@ -958,12 +958,12 @@ public interface FtpsEndpointBuilderFactory { * JDK IO API cannot always determine whether a file is currently being * used by another process. The option readLockCheckInterval can be used * to set the check frequency. fileLock - is for using - * java.nio.channels.FileLock. This option is not avail for the FTP - * component. This approach should be avoided when accessing a remote - * file system via a mount/share unless that file system supports - * distributed file locks. rename - rename is for using a try to rename - * the file as a test if we can get exclusive read-lock. idempotent - - * (only for file component) idempotent is for using a + * java.nio.channels.FileLock. This option is not avail for Windows OS + * and the FTP component. This approach should be avoided when accessing + * a remote file system via a mount/share unless that file system + * supports distributed file locks. rename - rename is for using a try + * to rename the file as a test if we can get exclusive read-lock. + * idempotent - (only for file component) idempotent is for using a * idempotentRepository as the read-lock. This allows to use read locks * that supports clustering if the idempotent repository implementation * supports that. idempotent-changed - (only for file component) diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/SftpEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/SftpEndpointBuilderFactory.java index 1592ac9..1a6e457 100644 --- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/SftpEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/SftpEndpointBuilderFactory.java @@ -848,12 +848,12 @@ public interface SftpEndpointBuilderFactory { * JDK IO API cannot always determine whether a file is currently being * used by another process. The option readLockCheckInterval can be used * to set the check frequency. fileLock - is for using - * java.nio.channels.FileLock. This option is not avail for the FTP - * component. This approach should be avoided when accessing a remote - * file system via a mount/share unless that file system supports - * distributed file locks. rename - rename is for using a try to rename - * the file as a test if we can get exclusive read-lock. idempotent - - * (only for file component) idempotent is for using a + * java.nio.channels.FileLock. This option is not avail for Windows OS + * and the FTP component. This approach should be avoided when accessing + * a remote file system via a mount/share unless that file system + * supports distributed file locks. rename - rename is for using a try + * to rename the file as a test if we can get exclusive read-lock. + * idempotent - (only for file component) idempotent is for using a * idempotentRepository as the read-lock. This allows to use read locks * that supports clustering if the idempotent repository implementation * supports that. idempotent-changed - (only for file component) diff --git a/examples/camel-example-cdi-cassandraql/src/main/java/org/apache/camel/example/cdi/cassandraql/Application.java b/examples/camel-example-cdi-cassandraql/src/main/java/org/apache/camel/example/cdi/cassandraql/Application.java index c43d1a5..d1f49c9 100644 --- a/examples/camel-example-cdi-cassandraql/src/main/java/org/apache/camel/example/cdi/cassandraql/Application.java +++ b/examples/camel-example-cdi-cassandraql/src/main/java/org/apache/camel/example/cdi/cassandraql/Application.java @@ -17,7 +17,6 @@ package org.apache.camel.example.cdi.cassandraql; import java.util.Arrays; -import java.util.Properties; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Produces; @@ -27,6 +26,7 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.cdi.ContextName; import org.apache.camel.component.properties.DefaultPropertiesParser; import org.apache.camel.component.properties.PropertiesComponent; +import org.apache.camel.component.properties.PropertiesLookup; import org.apache.camel.component.properties.PropertiesParser; import org.apache.deltaspike.core.api.config.ConfigResolver; @@ -65,7 +65,7 @@ public class Application { static class DeltaSpikeParser extends DefaultPropertiesParser { @Override - public String parseProperty(String key, String value, Properties properties) { + public String parseProperty(String key, String value, PropertiesLookup properties) { return ConfigResolver.getPropertyValue(key); } } diff --git a/examples/camel-example-cdi-properties/src/main/java/org/apache/camel/example/cdi/properties/Application.java b/examples/camel-example-cdi-properties/src/main/java/org/apache/camel/example/cdi/properties/Application.java index 4c48566..7537871 100644 --- a/examples/camel-example-cdi-properties/src/main/java/org/apache/camel/example/cdi/properties/Application.java +++ b/examples/camel-example-cdi-properties/src/main/java/org/apache/camel/example/cdi/properties/Application.java @@ -16,7 +16,6 @@ */ package org.apache.camel.example.cdi.properties; -import java.util.Properties; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Observes; import javax.enterprise.inject.Produces; @@ -28,6 +27,7 @@ import org.apache.camel.cdi.ContextName; import org.apache.camel.cdi.Uri; import org.apache.camel.component.properties.DefaultPropertiesParser; import org.apache.camel.component.properties.PropertiesComponent; +import org.apache.camel.component.properties.PropertiesLookup; import org.apache.camel.component.properties.PropertiesParser; import org.apache.camel.spi.CamelEvent.CamelContextStartedEvent; import org.apache.deltaspike.core.api.config.ConfigProperty; @@ -69,7 +69,7 @@ public class Application { static class DeltaSpikeParser extends DefaultPropertiesParser { @Override - public String parseProperty(String key, String value, Properties properties) { + public String parseProperty(String key, String value, PropertiesLookup properties) { return ConfigResolver.getPropertyValue(key); } }