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
The following commit(s) were added to refs/heads/master by this push: new 2926bbf CAMEL-15926: configure route templates from Java via interface 2926bbf is described below commit 2926bbf33286f33fa39049912aa1b165d1555a21 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Dec 8 10:25:57 2020 +0100 CAMEL-15926: configure route templates from Java via interface --- .../properties/DefaultPropertiesParser.java | 7 +++++- .../org/apache/camel/main/BaseMainSupport.java | 21 ---------------- .../apache/camel/main/ConfigureRouteTemplates.java | 28 ++++++++++++++++++++++ .../org/apache/camel/main/RoutesConfigurer.java | 7 ++++++ 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java index 71a4bf7..e83b20a 100644 --- a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java +++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java @@ -307,7 +307,12 @@ public class DefaultPropertiesParser implements PropertiesParser { } } - return parseProperty(key, value, properties); + // parse property may return null (such as when using spring boot and route templates) + String answer = parseProperty(key, value, properties); + if (answer == null) { + answer = value; + } + return answer; } } diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index e03c52e..62bf76f 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -452,27 +452,6 @@ public abstract class BaseMainSupport extends BaseService { // then configure and add the routes RoutesConfigurer configurer = new RoutesConfigurer(routesCollector, mainConfigurationProperties.getRoutesBuilders()); configurer.configureRoutes(camelContext, mainConfigurationProperties); - - // allow to do additional configuration after routes are configured - for (Object config : mainConfigurationProperties.getConfigurations()) { - // invoke configure method if exists - Method method = findMethod(config.getClass(), "configureRouteTemplates"); - if (method != null) { - LOG.info("Calling configureRouteTemplates method on configuration class: {}", config.getClass().getName()); - invokeMethod(method, config); - } else { - Object arg = camelContext; - method = findMethod(config.getClass(), "configureRouteTemplates", CamelContext.class); - if (method == null) { - method = findMethod(config.getClass(), "configureRouteTemplates", Main.class); - arg = this; - } - if (method != null) { - LOG.info("Calling configureRouteTemplates method on configuration class: {}", config.getClass().getName()); - invokeMethod(method, config, arg); - } - } - } } protected void postProcessCamelContext(CamelContext camelContext) throws Exception { diff --git a/core/camel-main/src/main/java/org/apache/camel/main/ConfigureRouteTemplates.java b/core/camel-main/src/main/java/org/apache/camel/main/ConfigureRouteTemplates.java new file mode 100644 index 0000000..20d2f2b --- /dev/null +++ b/core/camel-main/src/main/java/org/apache/camel/main/ConfigureRouteTemplates.java @@ -0,0 +1,28 @@ +/* + * 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.main; + +import org.apache.camel.CamelContext; + +/** + * Used for configuring and adding route templates such as using org.apache.camel.builder.TemplatedRouteBuilder. + */ +@FunctionalInterface +public interface ConfigureRouteTemplates { + + void configure(CamelContext camelContext); +} diff --git a/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java index 6b6e8f6..2d5b3b3 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java @@ -18,6 +18,7 @@ package org.apache.camel.main; import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.apache.camel.CamelContext; import org.apache.camel.RoutesBuilder; @@ -126,5 +127,11 @@ public class RoutesConfigurer { throw RuntimeCamelException.wrapRuntimeException(e); } } + + Set<ConfigureRouteTemplates> set = camelContext.getRegistry().findByType(ConfigureRouteTemplates.class); + for (ConfigureRouteTemplates crt : set) { + LOG.debug("Configuring route templates via: {}", crt); + crt.configure(camelContext); + } } }