Repository: camel Updated Branches: refs/heads/master 8100a0286 -> 23b653879
CAMEL-9469: Properties component - Should include component docs Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/23b65387 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/23b65387 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/23b65387 Branch: refs/heads/master Commit: 23b653879b4bf9dc095d301fde310baf8302950a Parents: 8100a02 Author: Claus Ibsen <[email protected]> Authored: Sun Jan 3 10:41:19 2016 +0100 Committer: Claus Ibsen <[email protected]> Committed: Sun Jan 3 11:14:11 2016 +0100 ---------------------------------------------------------------------- .../properties/PropertiesComponent.java | 44 ++++++- .../properties/PropertiesEndpoint.java | 119 +++++++++++++++++++ 2 files changed, 158 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/23b65387/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java index b076a42..77cbd6c 100644 --- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java +++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.Properties; import org.apache.camel.Endpoint; -import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.impl.UriEndpointComponent; import org.apache.camel.util.FilePathResolver; import org.apache.camel.util.LRUSoftCache; import org.apache.camel.util.ObjectHelper; @@ -34,10 +34,8 @@ import org.slf4j.LoggerFactory; /** * The <a href="http://camel.apache.org/properties">Properties Component</a> allows you to use property placeholders when defining Endpoint URIs - * - * @version */ -public class PropertiesComponent extends DefaultComponent { +public class PropertiesComponent extends UriEndpointComponent { /** * The default prefix token. @@ -109,6 +107,7 @@ public class PropertiesComponent extends DefaultComponent { private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_OVERRIDE; public PropertiesComponent() { + super(PropertiesEndpoint.class); // include out of the box functions addFunction(new EnvPropertiesFunction()); addFunction(new SysPropertiesFunction()); @@ -149,7 +148,12 @@ public class PropertiesComponent extends DefaultComponent { String endpointUri = parseUri(remaining, paths); LOG.debug("Endpoint uri parsed as: {}", endpointUri); - return getCamelContext().getEndpoint(endpointUri); + + Endpoint delegate = getCamelContext().getEndpoint(endpointUri); + PropertiesEndpoint answer = new PropertiesEndpoint(uri, delegate, this); + + setProperties(answer, parameters); + return answer; } public String parseUri(String uri) throws Exception { @@ -220,6 +224,10 @@ public class PropertiesComponent extends DefaultComponent { return locations; } + /** + * 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. + */ public void setLocations(String[] locations) { // make sure to trim as people may use new lines when configuring using XML // and do this in the setter as Spring/Blueprint resolves placeholders before Camel is being started @@ -233,6 +241,10 @@ public class PropertiesComponent extends DefaultComponent { this.locations = locations; } + /** + * 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. + */ public void setLocation(String location) { setLocations(location.split(",")); } @@ -255,6 +267,9 @@ public class PropertiesComponent extends DefaultComponent { return propertiesResolver; } + /** + * To use a custom PropertiesResolver + */ public void setPropertiesResolver(PropertiesResolver propertiesResolver) { this.propertiesResolver = propertiesResolver; } @@ -263,6 +278,9 @@ public class PropertiesComponent extends DefaultComponent { return propertiesParser; } + /** + * To use a custom PropertiesParser + */ public void setPropertiesParser(PropertiesParser propertiesParser) { this.propertiesParser = propertiesParser; } @@ -271,6 +289,9 @@ public class PropertiesComponent extends DefaultComponent { return cache; } + /** + * Whether or not to cache loaded properties. The default value is true. + */ public void setCache(boolean cache) { this.cache = cache; } @@ -279,6 +300,9 @@ public class PropertiesComponent extends DefaultComponent { return propertyPrefix; } + /** + * Optional prefix prepended to property names before resolution. + */ public void setPropertyPrefix(String propertyPrefix) { this.propertyPrefix = propertyPrefix; this.propertyPrefixResolved = propertyPrefix; @@ -291,6 +315,9 @@ public class PropertiesComponent extends DefaultComponent { return propertySuffix; } + /** + * Optional suffix appended to property names before resolution. + */ public void setPropertySuffix(String propertySuffix) { this.propertySuffix = propertySuffix; this.propertySuffixResolved = propertySuffix; @@ -303,6 +330,10 @@ public class PropertiesComponent extends DefaultComponent { return fallbackToUnaugmentedProperty; } + /** + * If true, first attempt resolution of property name augmented with propertyPrefix and propertySuffix + * before falling back the plain property name specified. If false, only the augmented property name is searched. + */ public void setFallbackToUnaugmentedProperty(boolean fallbackToUnaugmentedProperty) { this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty; } @@ -311,6 +342,9 @@ public class PropertiesComponent extends DefaultComponent { return ignoreMissingLocation; } + /** + * Whether to silently ignore if a location cannot be located, such as a properties file not found. + */ public void setIgnoreMissingLocation(boolean ignoreMissingLocation) { this.ignoreMissingLocation = ignoreMissingLocation; } http://git-wip-us.apache.org/repos/asf/camel/blob/23b65387/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java new file mode 100644 index 0000000..e9837a6 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java @@ -0,0 +1,119 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.properties; + +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.DelegateEndpoint; +import org.apache.camel.Endpoint; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; + +/** + * The properties component is used for using property placeholders in endpoint uris. + */ +@UriEndpoint(scheme = "properties", title = "Properties", syntax = "properties:key", label = "core,endpoint") +public class PropertiesEndpoint extends DefaultEndpoint implements DelegateEndpoint { + + private volatile Endpoint endpoint; + + @UriPath + @Metadata(required = "true") + private String key; + @UriParam + private String locations; + @UriParam + private boolean ignoreMissingLocation; + + public PropertiesEndpoint(String endpointUri, Endpoint delegate, Component component) { + super(endpointUri, component); + this.endpoint = delegate; + } + + public String getKey() { + return key; + } + + /** + * Property key to use as placeholder + */ + public void setKey(String key) { + this.key = key; + } + + public String getLocations() { + return locations; + } + + /** + * 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. + */ + public void setLocations(String locations) { + this.locations = locations; + } + + public boolean isIgnoreMissingLocation() { + return ignoreMissingLocation; + } + + /** + * Whether to silently ignore if a location cannot be located, such as a properties file not found. + */ + public void setIgnoreMissingLocation(boolean ignoreMissingLocation) { + this.ignoreMissingLocation = ignoreMissingLocation; + } + + @Override + public Producer createProducer() throws Exception { + return endpoint.createProducer(); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + return endpoint.createConsumer(processor); + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public Endpoint getEndpoint() { + return endpoint; + } + + @Override + protected void doStart() throws Exception { + // add the endpoint as a service so Camel can manage the endpoint and enlist the endpoint in JMX etc. + getCamelContext().addService(endpoint); + super.doStart(); + } + + @Override + protected void doStop() throws Exception { + super.doStop(); + // noop + } + +}
