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 367b534f56efbb26b88a45866c908fad0b38f0f1 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Sep 26 12:00:28 2019 +0200 CAMEL-13947: PropertiesComponent should be a static service and resolved like other similar features. --- components/camel-jasypt/pom.xml | 3 +- .../apache/camel/zipkin/ServiceHostFunction.java | 67 ++++++++++++++++++++++ .../apache/camel/zipkin/ServicePortFunction.java | 67 ++++++++++++++++++++++ .../java/org/apache/camel/zipkin/ZipkinTracer.java | 10 ++-- components/readme.adoc | 2 +- docs/components/modules/ROOT/nav.adoc | 1 - .../components/modules/ROOT/pages/spring-boot.adoc | 12 +++- .../modules/ROOT/pages/properties-component.adoc | 17 +----- 8 files changed, 153 insertions(+), 26 deletions(-) diff --git a/components/camel-jasypt/pom.xml b/components/camel-jasypt/pom.xml index 4eeab49..0ab2078 100644 --- a/components/camel-jasypt/pom.xml +++ b/components/camel-jasypt/pom.xml @@ -42,9 +42,10 @@ <dependencies> + <!-- extends properties component from camel-base --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-support</artifactId> + <artifactId>camel-base</artifactId> </dependency> <dependency> diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ServiceHostFunction.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ServiceHostFunction.java new file mode 100644 index 0000000..ee71221 --- /dev/null +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ServiceHostFunction.java @@ -0,0 +1,67 @@ +/* + * 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.zipkin; + +import java.util.Locale; + +import org.apache.camel.util.StringHelper; + +/** + * A function that lookup the property value from + * OS environment variables using the service idiom. + * <p/> + * A service is defined using two environment variables where name is name of the service: + * <ul> + * <li><tt>NAME_SERVICE_HOST</tt></li> + * <li><tt>NAME_SERVICE_PORT</tt></li> + * </ul> + * in other words the service uses <tt>_SERVICE_HOST</tt> and <tt>_SERVICE_PORT</tt> as prefix. + * <p/> + * This implementation is to return the host part only. + */ +public class ServiceHostFunction { + + private static final String HOST_PREFIX = "_SERVICE_HOST"; + + public static String apply(String remainder) { + String key = remainder; + String defaultValue = null; + + if (remainder.contains(":")) { + key = StringHelper.before(remainder, ":"); + defaultValue = StringHelper.after(remainder, ":"); + } + + // make sure to use upper case + if (key != null) { + // make sure to use underscore as dash is not supported as ENV variables + key = key.toUpperCase(Locale.ENGLISH).replace('-', '_'); + + // a service should have both the host and port defined + String host = System.getenv(key + HOST_PREFIX); + + if (host != null) { + return host; + } else { + return defaultValue; + } + } + + return defaultValue; + } + +} diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ServicePortFunction.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ServicePortFunction.java new file mode 100644 index 0000000..65ada3f --- /dev/null +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ServicePortFunction.java @@ -0,0 +1,67 @@ +/* + * 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.zipkin; + +import java.util.Locale; + +import org.apache.camel.util.StringHelper; + +/** + * A function that lookup the property value from + * OS environment variables using the service idiom. + * <p/> + * A service is defined using two environment variables where name is name of the service: + * <ul> + * <li><tt>NAME_SERVICE_HOST</tt></li> + * <li><tt>NAME_SERVICE_PORT</tt></li> + * </ul> + * in other words the service uses <tt>_SERVICE_HOST</tt> and <tt>_SERVICE_PORT</tt> as prefix. + * <p/> + * This implementation is to return the port part only. + */ +public class ServicePortFunction { + + private static final String PORT_PREFIX = "_SERVICE_PORT"; + + public static String apply(String remainder) { + String key = remainder; + String defaultValue = null; + + if (remainder.contains(":")) { + key = StringHelper.before(remainder, ":"); + defaultValue = StringHelper.after(remainder, ":"); + } + + // make sure to use upper case + if (key != null) { + // make sure to use underscore as dash is not supported as ENV variables + key = key.toUpperCase(Locale.ENGLISH).replace('-', '_'); + + // a service should have both the host and port defined + String port = System.getenv(key + PORT_PREFIX); + + if (port != null) { + return port; + } else { + return defaultValue; + } + } + + return defaultValue; + } +} + diff --git a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java index eac9963..23495be 100644 --- a/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java +++ b/components/camel-zipkin/src/main/java/org/apache/camel/zipkin/ZipkinTracer.java @@ -47,8 +47,6 @@ import org.apache.camel.RuntimeCamelException; import org.apache.camel.StaticService; import org.apache.camel.api.management.ManagedAttribute; import org.apache.camel.api.management.ManagedResource; -import org.apache.camel.component.properties.ServiceHostPropertiesFunction; -import org.apache.camel.component.properties.ServicePortPropertiesFunction; import org.apache.camel.spi.CamelEvent; import org.apache.camel.spi.CamelEvent.ExchangeSendingEvent; import org.apache.camel.spi.CamelEvent.ExchangeSentEvent; @@ -400,16 +398,16 @@ public class ZipkinTracer extends ServiceSupport implements RoutePolicyFactory, } else { // is there a zipkin service setup as ENV variable to auto // register a span reporter - String host = new ServiceHostPropertiesFunction().apply(ZIPKIN_COLLECTOR_HTTP_SERVICE); - String port = new ServicePortPropertiesFunction().apply(ZIPKIN_COLLECTOR_HTTP_SERVICE); + String host = ServiceHostFunction.apply(ZIPKIN_COLLECTOR_HTTP_SERVICE); + String port = ServicePortFunction.apply(ZIPKIN_COLLECTOR_HTTP_SERVICE); if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) { LOG.info("Auto-configuring Zipkin URLConnectionSender using host: {} and port: {}", host, port); int num = camelContext.getTypeConverter().mandatoryConvertTo(Integer.class, port); String implicitEndpoint = "http://" + host + ":" + num + "/api/v2/spans"; spanReporter = AsyncReporter.create(URLConnectionSender.create(implicitEndpoint)); } else { - host = new ServiceHostPropertiesFunction().apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE); - port = new ServicePortPropertiesFunction().apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE); + host = ServiceHostFunction.apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE); + port = ServicePortFunction.apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE); if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) { LOG.info("Auto-configuring Zipkin ScribeSpanCollector using host: {} and port: {}", host, port); int num = camelContext.getTypeConverter().mandatoryConvertTo(Integer.class, port); diff --git a/components/readme.adoc b/components/readme.adoc index bcd84da..6afad73 100644 --- a/components/readme.adoc +++ b/components/readme.adoc @@ -1062,7 +1062,7 @@ Number of Languages: 17 in 11 JAR artifacts (0 deprecated) == Miscellaneous Components // others: START -Number of Miscellaneous Components: 36 in 36 JAR artifacts (0 deprecated) +Number of Miscellaneous Components: 35 in 35 JAR artifacts (0 deprecated) [width="100%",cols="4,1,5",options="header"] |=== diff --git a/docs/components/modules/ROOT/nav.adoc b/docs/components/modules/ROOT/nav.adoc index 0a3ca76..63de0c6 100644 --- a/docs/components/modules/ROOT/nav.adoc +++ b/docs/components/modules/ROOT/nav.adoc @@ -273,7 +273,6 @@ * xref:pg-replication-slot-component.adoc[PostgresSQL Replication Slot Component] * xref:pgevent-component.adoc[PostgresSQL Event Component] * xref:lpr-component.adoc[Printer Component] -* xref:properties-component.adoc[Properties Component] * xref:protobuf-dataformat.adoc[Protobuf DataFormat] * xref:pubnub-component.adoc[PubNub Component] * xref:pulsar-component.adoc[Apache Pulsar Component] diff --git a/docs/components/modules/ROOT/pages/spring-boot.adoc b/docs/components/modules/ROOT/pages/spring-boot.adoc index 3ed2e85..e7660cf 100644 --- a/docs/components/modules/ROOT/pages/spring-boot.adoc +++ b/docs/components/modules/ROOT/pages/spring-boot.adoc @@ -90,7 +90,7 @@ When using Spring Boot make sure to use the following Maven dependency to have s ---- -The component supports 129 options, which are listed below. +The component supports 139 options, which are listed below. @@ -124,6 +124,16 @@ The component supports 129 options, which are listed below. | *camel.clustered.controller.namespace* | The default namespace. | | String | *camel.clustered.controller.routes* | Routes configuration. | | Map | *camel.component.enabled* | Global option to enable/disable component auto-configuration, default is true. | true | Boolean +| *camel.component.properties.auto-discover-properties-sources* | Whether to automatically discovery instances of PropertiesSource from registry and service factory. | true | Boolean +| *camel.component.properties.default-fallback-enabled* | If false, the component does not attempt to find a default for the key by looking after the colon separator. | true | Boolean +| *camel.component.properties.encoding* | Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented by java.util.Properties#load(java.io.InputStream) | | String +| *camel.component.properties.environment-variable-mode* | 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 | Integer +| *camel.component.properties.ignore-missing-location* | Whether to silently ignore if a location cannot be located, such as a properties file not found. | false | Boolean +| *camel.component.properties.initial-properties* | Sets initial properties which will be used before any locations are resolved. The option is a java.util.Properties type. | | String +| *camel.component.properties.location* | A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option. | | String +| *camel.component.properties.override-properties* | Sets a special list of override properties that take precedence and will use first, if a property exist. The option is a java.util.Properties type. | | String +| *camel.component.properties.properties-parser* | To use a custom PropertiesParser. The option is a org.apache.camel.component.properties.PropertiesParser type. | | String +| *camel.component.properties.system-properties-mode* | 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 | Integer | *camel.dataformat.enabled* | Global option to enable/disable dataformat auto-configuration, default is true. | true | Boolean | *camel.health.check.routes.enabled* | Global option to enable/disable Camel extended health check for routes, default is false. | false | Boolean | *camel.health.check.routes.threshold* | General health check configurations. | | Map diff --git a/docs/components/modules/ROOT/pages/properties-component.adoc b/docs/user-manual/modules/ROOT/pages/properties-component.adoc similarity index 98% rename from docs/components/modules/ROOT/pages/properties-component.adoc rename to docs/user-manual/modules/ROOT/pages/properties-component.adoc index d160a2a..a8d1e68 100644 --- a/docs/components/modules/ROOT/pages/properties-component.adoc +++ b/docs/user-manual/modules/ROOT/pages/properties-component.adoc @@ -1,6 +1,6 @@ [[properties-component]] = Properties Component -:page-source: components/camel-properties/src/main/docs/properties-component.adoc +:page-source: core/camel-base/src/main/docs/properties-component.adoc *Available as of Camel version 2.3* @@ -72,22 +72,8 @@ with the following path and query parameters: |=== // endpoint options: END -// spring-boot-auto-configure options: START == Spring Boot Auto-Configuration -When using Spring Boot make sure to use the following Maven dependency to have support for auto configuration: - -[source,xml] ----- -<dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-properties-starter</artifactId> - <version>x.x.x</version> - <!-- use the same version as your Camel core version --> -</dependency> ----- - - The component supports 10 options, which are listed below. @@ -106,7 +92,6 @@ The component supports 10 options, which are listed below. | *camel.component.properties.properties-parser* | To use a custom PropertiesParser. The option is a org.apache.camel.component.properties.PropertiesParser type. | | String | *camel.component.properties.system-properties-mode* | 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 | Integer |=== -// spring-boot-auto-configure options: END [TIP] **Resolving property from Java code** +