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 cf12f9c23bd82d0f8c6f0558c1e0445bb1da897e Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Aug 13 13:12:07 2019 +0200 CAMEL-13850: Remove resolvePropertyPlaceholders on DefaultComponent as this is already supported via camel main, spring boot and other means. This avoid reflection overhead on bootstrap. --- MIGRATION.md | 3 + .../org/apache/camel/support/DefaultComponent.java | 31 --------- .../camel/support/PropertyPlaceholdersHelper.java | 80 ---------------------- 3 files changed, 3 insertions(+), 111 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index a182b1e..eb7b949 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -382,6 +382,9 @@ The `Component` and `DataFormat` interfaces now extend `Service` as components a The class `FactoryFinder` has changed its API to use `Optional` as return types instead of throwing checked `FactoryNotFoundException` or `ClassNotFoundException` etc. +The option `resolvePropertyPlaceholders` on all the components has been removed, +as property placeholders is already supported via Camel Main, Camel Spring Boot and other means. + #### camel-test If you are using camel-test and override the `createRegistry` method, for example to register beans from the `JndiRegisty` class, then this is no longer necessary, and instead diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java index ce0f8a8..7d4b73d 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java @@ -34,7 +34,6 @@ import org.apache.camel.Endpoint; import org.apache.camel.ResolveEndpointFailedException; import org.apache.camel.component.extension.ComponentExtension; import org.apache.camel.spi.Metadata; -import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.support.service.ServiceSupport; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.URISupport; @@ -55,9 +54,6 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone private CamelContext camelContext; - @Metadata(label = "advanced", defaultValue = "true", - description = "Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.") - private boolean resolvePropertyPlaceholders = true; @Metadata(label = "advanced", description = "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities") private boolean basicPropertyBinding; @@ -230,22 +226,6 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone } /** - * Whether the component should resolve property placeholders on itself when starting. - * Only properties which are of String type can use property placeholders. - */ - public void setResolvePropertyPlaceholders(boolean resolvePropertyPlaceholders) { - this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; - } - - /** - * Whether the component should resolve property placeholders on itself when starting. - * Only properties which are of String type can use property placeholders. - */ - public boolean isResolvePropertyPlaceholders() { - return resolvePropertyPlaceholders; - } - - /** * Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities. */ public boolean isBasicPropertyBinding() { @@ -340,17 +320,6 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone @Override protected void doStart() throws Exception { ObjectHelper.notNull(getCamelContext(), "camelContext"); - - if (isResolvePropertyPlaceholders()) { - // only resolve property placeholders if its in use - PropertiesComponent existing = camelContext.getPropertiesComponent(false); - if (existing != null) { - log.debug("Resolving property placeholders on component: {}", this); - PropertyPlaceholdersHelper.resolvePropertyPlaceholders(camelContext, this); - } else { - log.debug("Cannot resolve property placeholders on component: {} as PropertiesComponent is not in use", this); - } - } } @Override diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyPlaceholdersHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyPlaceholdersHelper.java deleted file mode 100644 index 84e44e9..0000000 --- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyPlaceholdersHelper.java +++ /dev/null @@ -1,80 +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.support; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.camel.CamelContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class PropertyPlaceholdersHelper { - - private static final Logger LOG = LoggerFactory.getLogger(PropertyPlaceholdersHelper.class); - - private PropertyPlaceholdersHelper() { - } - - /** - * Inspects the given definition and resolves any property placeholders from its properties. - * <p/> - * This implementation will check all the getter/setter pairs on this instance and for all the values - * (which is a String type) will be property placeholder resolved. - * - * @param camelContext the Camel context - * @param object the object - * @throws Exception is thrown if property placeholders was used and there was an error resolving them - * @see CamelContext#resolvePropertyPlaceholders(String) - * @see org.apache.camel.spi.PropertiesComponent - */ - public static void resolvePropertyPlaceholders(CamelContext camelContext, Object object) throws Exception { - LOG.trace("Resolving property placeholders for: {}", object); - - // TODO: Like ProcessorDefinitionHelper we want to avoid reflection - - // find all getter/setter which we can use for property placeholders - Map<String, Object> properties = new HashMap<>(); - IntrospectionSupport.getProperties(object, properties, null); - - if (!properties.isEmpty()) { - LOG.trace("There are {} properties on: {}", properties.size(), object); - // lookup and resolve properties for String based properties - for (Map.Entry<String, Object> entry : properties.entrySet()) { - // the name is always a String - String name = entry.getKey(); - Object value = entry.getValue(); - if (value instanceof String) { - // value must be a String, as a String is the key for a property placeholder - String text = (String) value; - text = camelContext.resolvePropertyPlaceholders(text); - if (text != value) { - // invoke setter as the text has changed - boolean changed = IntrospectionSupport.setProperty(camelContext.getTypeConverter(), object, name, text); - if (!changed) { - throw new IllegalArgumentException("No setter to set property: " + name + " to: " + text + " on: " + object); - } - if (LOG.isDebugEnabled()) { - LOG.debug("Changed property [{}] from: {} to: {}", name, value, text); - } - } - } - } - } - } - -}