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 b5e8b2d4dbb5608aec265028382de39016437bdd Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Jul 4 09:38:59 2019 +0200 CAMEL-13721: Properties component - Make it simpler by removing not often used stuff --- MIGRATION.md | 2 +- .../src/main/docs/properties-component.adoc | 3 +- .../properties/DefaultPropertiesResolver.java | 193 --------------------- .../component/properties/PropertiesComponent.java | 23 --- .../component/properties/PropertiesResolver.java | 43 ----- .../component/properties/RefPropertiesSource.java | 2 - .../core/xml/AbstractCamelContextFactoryBean.java | 8 - .../xml/CamelPropertyPlaceholderDefinition.java | 13 -- .../PropertiesComponentConfiguration.java | 18 -- 9 files changed, 2 insertions(+), 303 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 7ceaf02..a13dfd2 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -89,7 +89,7 @@ The Camel `Main` class has been moved out of `camel-core` into `camel-main` so y ### Properties component -The `properties` component has some advanced options removed: `propertyPrefix`, `propertySuffix`, and `fallbackToUnaugmented`; these options was never really useable for end users anyway. +The `properties` component has some advanced options removed: `propertyPrefix`, `propertySuffix`, and `fallbackToUnaugmented`; these options was never really useable for end users anyway. The option `propertiesResolver` has also been removed as you should use `PropertiesSource` instead. ### Removed components diff --git a/components/camel-properties/src/main/docs/properties-component.adoc b/components/camel-properties/src/main/docs/properties-component.adoc index ae8154c..cfe96df 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 16 options, which are listed below. +The Properties component supports 15 options, which are listed below. @@ -25,7 +25,6 @@ The Properties component supports 16 options, which are listed below. | *locations* (common) | A list of locations to load properties. This option will override any default locations and only use the locations from this option. | | List | *location* (common) | 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 | *encoding* (common) | 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 -| *propertiesResolver* (common) | *Deprecated* To use a custom PropertiesResolver | | PropertiesResolver | *propertiesParser* (common) | To use a custom PropertiesParser | | PropertiesParser | *cache* (common) | Whether or not to cache loaded properties. The default value is true. | true | boolean | *defaultFallbackEnabled* (common) | If false, the component does not attempt to find a default for the key by looking after the colon separator. | true | boolean diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java deleted file mode 100644 index a88c587..0000000 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.camel.CamelContext; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.util.IOHelper; -import org.apache.camel.util.OrderedProperties; - -/** - * Default {@link org.apache.camel.component.properties.PropertiesResolver} which can resolve properties - * from file and classpath. - * <p/> - * You can denote <tt>classpath:</tt> or <tt>file:</tt> as prefix in the uri to select whether the file - * is located in the classpath or on the file system. - */ -@Deprecated -public class DefaultPropertiesResolver implements PropertiesResolver { - - private final PropertiesComponent propertiesComponent; - - public DefaultPropertiesResolver(PropertiesComponent propertiesComponent) { - this.propertiesComponent = propertiesComponent; - } - - public Properties resolveProperties(CamelContext context, boolean ignoreMissingLocation, List<PropertiesLocation> locations) { - Properties answer = new OrderedProperties(); - Properties prop; - - for (PropertiesLocation location : locations) { - switch(location.getResolver()) { - case "ref": - prop = loadPropertiesFromRegistry(context, ignoreMissingLocation, location); - prop = prepareLoadedProperties(prop); - answer.putAll(prop); - break; - case "file": - prop = loadPropertiesFromFilePath(context, ignoreMissingLocation, location); - prop = prepareLoadedProperties(prop); - answer.putAll(prop); - break; - case "classpath": - default: - // default to classpath - prop = loadPropertiesFromClasspath(context, ignoreMissingLocation, location); - prop = prepareLoadedProperties(prop); - answer.putAll(prop); - break; - } - } - - return answer; - } - - protected Properties loadPropertiesFromFilePath(CamelContext context, boolean ignoreMissingLocation, PropertiesLocation location) { - Properties answer = new OrderedProperties(); - String path = location.getPath(); - - InputStream is = null; - Reader reader = null; - try { - is = new FileInputStream(path); - if (propertiesComponent.getEncoding() != null) { - reader = new BufferedReader(new InputStreamReader(is, propertiesComponent.getEncoding())); - answer.load(reader); - } else { - answer.load(is); - } - } catch (FileNotFoundException e) { - if (!ignoreMissingLocation && !location.isOptional()) { - throw RuntimeCamelException.wrapRuntimeCamelException(e); - } - } catch (IOException e) { - throw RuntimeCamelException.wrapRuntimeCamelException(e); - } finally { - IOHelper.close(reader, is); - } - - return answer; - } - - protected Properties loadPropertiesFromClasspath(CamelContext context, boolean ignoreMissingLocation, PropertiesLocation location) { - Properties answer = new OrderedProperties(); - String path = location.getPath(); - - InputStream is = context.getClassResolver().loadResourceAsStream(path); - Reader reader = null; - if (is == null) { - if (!ignoreMissingLocation && !location.isOptional()) { - throw RuntimeCamelException.wrapRuntimeCamelException(new FileNotFoundException("Properties file " + path + " not found in classpath")); - } - } else { - try { - if (propertiesComponent.getEncoding() != null) { - reader = new BufferedReader(new InputStreamReader(is, propertiesComponent.getEncoding())); - answer.load(reader); - } else { - answer.load(is); - } - } catch (IOException e) { - throw RuntimeCamelException.wrapRuntimeCamelException(e); - } finally { - IOHelper.close(reader, is); - } - } - return answer; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - protected Properties loadPropertiesFromRegistry(CamelContext context, boolean ignoreMissingLocation, PropertiesLocation location) { - String path = location.getPath(); - Properties answer; - try { - answer = context.getRegistry().lookupByNameAndType(path, Properties.class); - } catch (Exception ex) { - // just look up the Map as a fault back - Map map = context.getRegistry().lookupByNameAndType(path, Map.class); - answer = new OrderedProperties(); - answer.putAll(map); - } - if (answer == null && (!ignoreMissingLocation && !location.isOptional())) { - throw RuntimeCamelException.wrapRuntimeCamelException(new FileNotFoundException("Properties " + path + " not found in registry")); - } - return answer != null ? answer : new OrderedProperties(); - } - - /** - * Strategy to prepare loaded properties before being used by Camel. - * <p/> - * This implementation will ensure values are trimmed, as loading properties from - * a file with values having trailing spaces is not automatic trimmed by the Properties API - * from the JDK. - * - * @param properties the properties - * @return the prepared properties - */ - protected Properties prepareLoadedProperties(Properties properties) { - Properties answer = new OrderedProperties(); - for (Map.Entry<Object, Object> entry : properties.entrySet()) { - Object key = entry.getKey(); - Object value = entry.getValue(); - if (value instanceof String) { - String s = (String) value; - - // trim any trailing spaces which can be a problem when loading from - // a properties file, note that java.util.Properties does already this - // for any potential leading spaces so there's nothing to do there - value = trimTrailingWhitespaces(s); - } - answer.put(key, value); - } - return answer; - } - - private static String trimTrailingWhitespaces(String s) { - int endIndex = s.length(); - for (int index = s.length() - 1; index >= 0; index--) { - if (s.charAt(index) == ' ') { - endIndex = index; - } else { - break; - } - } - String answer = s.substring(0, endIndex); - return answer; - } - -} 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 f706125..84a00c8 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 @@ -56,7 +56,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. // TODO: sources and locationSources merged into 1 // TODO: cache to DefaultPropertiesLookup // TODO: API on PropertiesComponent in SPI to Optional<String> lookupProperty(String name); - // TODO: Remove PropertiesResolver /** * Never check system properties. @@ -105,7 +104,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. private static final Logger LOG = LoggerFactory.getLogger(PropertiesComponent.class); private final Map<String, PropertiesFunction> functions = new LinkedHashMap<>(); - private PropertiesResolver propertiesResolver; private PropertiesParser propertiesParser = new DefaultPropertiesParser(this); private final PropertiesLookup propertiesLookup = new DefaultPropertiesLookup(this); private final List<PropertiesSource> sources = new ArrayList<>(); @@ -217,14 +215,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. } } - // use legacy properties resolver - if (propertiesResolver != null) { - Properties p = propertiesResolver.resolveProperties(getCamelContext(), ignoreMissingLocation, locations); - if (p != null && !p.isEmpty()) { - prop.putAll(p); - } - } - // use override properties if (overrideProperties != null) { // make a copy to avoid affecting the original properties @@ -342,19 +332,6 @@ public class PropertiesComponent extends DefaultComponent implements org.apache. this.encoding = encoding; } - @Deprecated - public PropertiesResolver getPropertiesResolver() { - return propertiesResolver; - } - - /** - * To use a custom PropertiesResolver - */ - @Deprecated - public void setPropertiesResolver(PropertiesResolver propertiesResolver) { - this.propertiesResolver = propertiesResolver; - } - public PropertiesParser getPropertiesParser() { return propertiesParser; } diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesResolver.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesResolver.java deleted file mode 100644 index f6f9399..0000000 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesResolver.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.List; -import java.util.Properties; - -import org.apache.camel.CamelContext; - -/** - * A resolver to load properties from a given source such as a file from a classpath. - * <p/> - * Implementations can also load properties from another source source as JNDI. - */ -@Deprecated -public interface PropertiesResolver { - - /** - * Resolve properties from the given uri - * - * @param context the camel context - * @param ignoreMissingLocation ignore silently if the property file is missing - * @param locations location(s) defining the source(s) - * @return the properties - * @throws java.io.IOError is thrown if resolving the properties failed - */ - @Deprecated - Properties resolveProperties(CamelContext context, boolean ignoreMissingLocation, List<PropertiesLocation> locations); -} diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java index ad99eef..fb4155c 100644 --- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java +++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/RefPropertiesSource.java @@ -64,8 +64,6 @@ public class RefPropertiesSource implements LocationPropertiesSource { } else if (obj instanceof Map) { answer = new OrderedProperties(); answer.putAll((Map<?, ?>) obj); - } else if (obj instanceof PropertiesResolver) { - // ignore } else if (!propertiesComponent.isIgnoreMissingLocation() && !location.isOptional()) { throw RuntimeCamelException.wrapRuntimeCamelException(new FileNotFoundException("Properties " + path + " not found in registry")); } diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java index 359ba9a..c3503db 100644 --- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java +++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java @@ -46,7 +46,6 @@ import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.component.properties.PropertiesFunction; import org.apache.camel.component.properties.PropertiesLocation; import org.apache.camel.component.properties.PropertiesParser; -import org.apache.camel.component.properties.PropertiesResolver; import org.apache.camel.health.HealthCheckRegistry; import org.apache.camel.health.HealthCheckRepository; import org.apache.camel.health.HealthCheckService; @@ -642,13 +641,6 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex pc.setIgnoreMissingLocation(def.isIgnoreMissingLocation()); } - // if using a custom resolver - if (org.apache.camel.util.ObjectHelper.isNotEmpty(def.getPropertiesResolverRef())) { - PropertiesResolver resolver = CamelContextHelper.mandatoryLookup(getContext(), def.getPropertiesResolverRef(), - PropertiesResolver.class); - pc.setPropertiesResolver(resolver); - } - // if using a custom parser if (org.apache.camel.util.ObjectHelper.isNotEmpty(def.getPropertiesParserRef())) { PropertiesParser parser = CamelContextHelper.mandatoryLookup(getContext(), def.getPropertiesParserRef(), diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java index c9772fa..c7cdcd5 100644 --- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java +++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java @@ -43,8 +43,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { @XmlAttribute @Metadata(defaultValue = "false") private Boolean ignoreMissingLocation; @XmlAttribute - private String propertiesResolverRef; - @XmlAttribute private String propertiesParserRef; @XmlAttribute @Metadata(defaultValue = "true") private Boolean defaultFallbackEnabled; @@ -94,17 +92,6 @@ public class CamelPropertyPlaceholderDefinition extends IdentifiedType { this.cache = cache; } - public String getPropertiesResolverRef() { - return propertiesResolverRef; - } - - /** - * Reference to a custom PropertiesResolver to be used - */ - public void setPropertiesResolverRef(String propertiesResolverRef) { - this.propertiesResolverRef = propertiesResolverRef; - } - public String getPropertiesParserRef() { return propertiesParserRef; } 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 7bda5fc..e43057c 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 @@ -21,7 +21,6 @@ import javax.annotation.Generated; import org.apache.camel.component.properties.PropertiesLocation; import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; /** * The properties component is used for using property placeholders in endpoint @@ -59,12 +58,6 @@ public class PropertiesComponentConfiguration */ private String encoding; /** - * To use a custom PropertiesResolver. The option is a - * org.apache.camel.component.properties.PropertiesResolver type. - */ - @Deprecated - private String propertiesResolver; - /** * To use a custom PropertiesParser. The option is a * org.apache.camel.component.properties.PropertiesParser type. */ @@ -153,17 +146,6 @@ public class PropertiesComponentConfiguration this.encoding = encoding; } - @Deprecated - @DeprecatedConfigurationProperty - public String getPropertiesResolver() { - return propertiesResolver; - } - - @Deprecated - public void setPropertiesResolver(String propertiesResolver) { - this.propertiesResolver = propertiesResolver; - } - public String getPropertiesParser() { return propertiesParser; }