You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/12/08 09:35:13 UTC

[camel-spring-boot] branch master updated: CAMEL-15926: spring boot now support route templates

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-spring-boot.git


The following commit(s) were added to refs/heads/master by this push:
     new a2469ff  CAMEL-15926: spring boot now support route templates
a2469ff is described below

commit a2469ff0ad79dc98b7382c96b1bb086c8d241cd9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 8 10:33:52 2020 +0100

    CAMEL-15926: spring boot now support route templates
---
 .../src/main/docs/spring-boot.adoc                 |  3 +-
 .../CamelRouteTemplateAutoConfiguration.java       | 57 ++++++++++++++++++++++
 .../CamelRouteTemplateConfigurationProperties.java | 41 ++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   |  3 +-
 4 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.adoc b/core/camel-spring-boot/src/main/docs/spring-boot.adoc
index 9608895..21d142c 100644
--- a/core/camel-spring-boot/src/main/docs/spring-boot.adoc
+++ b/core/camel-spring-boot/src/main/docs/spring-boot.adoc
@@ -92,7 +92,7 @@ When using spring-boot with Spring Boot make sure to use the following Maven dep
 ----
 
 
-The component supports 159 options, which are listed below.
+The component supports 160 options, which are listed below.
 
 
 
@@ -146,6 +146,7 @@ The component supports 159 options, which are listed below.
 | *camel.health.registry-enabled* | Whether registry health check is enabled Is default enabled |  | Boolean
 | *camel.health.routes-enabled* | Whether routes health check is enabled Is default enabled |  | Boolean
 | *camel.language.enabled* | Global option to enable/disable language auto-configuration, default is true. | true | Boolean
+| *camel.routetemplate.config* |  |  | List
 | *camel.springboot.allow-use-original-message* | Sets whether to allow access to the original message from Camel's error handler, or from org.apache.camel.spi.UnitOfWork.getOriginalInMessage(). Turning this off can optimize performance, as defensive copy of the original message is not needed. Default is false. | false | Boolean
 | *camel.springboot.auto-startup* | Sets whether the object should automatically start when Camel starts. Important: Currently only routes can be disabled, as CamelContext's are always started. Note: When setting auto startup false on CamelContext then that takes precedence and no routes is started. You would need to start CamelContext explicit using the org.apache.camel.CamelContext.start() method, to start the context, and then you would need to start the routes manually using Camelcon [...]
 | *camel.springboot.autowired-enabled* | Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. Default is true. | true | Boolean
diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/routetemplate/CamelRouteTemplateAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/routetemplate/CamelRouteTemplateAutoConfiguration.java
new file mode 100644
index 0000000..437e73b
--- /dev/null
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/routetemplate/CamelRouteTemplateAutoConfiguration.java
@@ -0,0 +1,57 @@
+/*
+ * 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.spring.boot.routetemplate;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.main.PropertiesRouteTemplateParametersSource;
+import org.apache.camel.spi.RouteTemplateParameterSource;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(CamelRouteTemplateConfigurationProperties.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+public class CamelRouteTemplateAutoConfiguration {
+
+    @Bean
+    public RouteTemplateParameterSource routeTemplate(CamelContext camelContext, CamelRouteTemplateConfigurationProperties rt) {
+        if (rt.getConfig() == null) {
+            return null;
+        }
+
+        PropertiesRouteTemplateParametersSource source = new PropertiesRouteTemplateParametersSource();
+        int counter = 0;
+        for (Map<String, String> e : rt.getConfig()) {
+            for (Map.Entry<String, String> entry : e.entrySet()) {
+                source.addParameter(String.valueOf(counter), entry.getKey(), entry.getValue());
+            }
+            counter++;
+        }
+
+        camelContext.getRegistry().bind("CamelSpringBootRouteTemplateParametersSource", RouteTemplateParameterSource.class, source);
+
+        return source;
+    }
+
+}
diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/routetemplate/CamelRouteTemplateConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/routetemplate/CamelRouteTemplateConfigurationProperties.java
new file mode 100644
index 0000000..6c7936b
--- /dev/null
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/routetemplate/CamelRouteTemplateConfigurationProperties.java
@@ -0,0 +1,41 @@
+/*
+ * 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.spring.boot.routetemplate;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.routetemplate")
+public class CamelRouteTemplateConfigurationProperties {
+
+    private List<Map<String, String>> config;
+
+    public List<Map<String, String>> getConfig() {
+        return config;
+    }
+
+    /**
+     * Route template configurations
+     */
+    public void setConfig(List<Map<String, String>> config) {
+        this.config = config;
+    }
+}
+
+
diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring.factories b/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
index a81fc4c..38f8a24 100644
--- a/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
+++ b/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
@@ -43,5 +43,6 @@ org.apache.camel.spring.boot.cloud.CamelCloudServiceChooserAutoConfiguration,\
 org.apache.camel.spring.boot.cluster.ClusteredRouteControllerAutoConfiguration,\
 org.apache.camel.spring.boot.properties.PropertiesComponentAutoConfiguration,\
 org.apache.camel.spring.boot.security.CamelSSLAutoConfiguration,\
-org.apache.camel.spring.boot.threadpool.CamelThreadPoolAutoConfiguration
+org.apache.camel.spring.boot.threadpool.CamelThreadPoolAutoConfiguration,\
+org.apache.camel.spring.boot.routetemplate.CamelRouteTemplateAutoConfiguration