This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git

commit c8f7d977cd11707c1dbcf4e7cf8feefb7a1bddad
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Jun 4 21:12:59 2022 +0200

    CAMEL-18166: camel-spring-boot - Add support for endpoint-dsl route 
collector using @Bean style.
---
 .../camel/spring/boot/CamelAutoConfiguration.java  |  2 +
 .../src/main/resources/META-INF/spring.factories   | 16 ------
 dsl-starter/camel-endpointdsl-starter/pom.xml      |  5 ++
 .../endpointdsl/EndpointDslAutoConfiguration.java  | 35 +++++++++++++
 .../endpointdsl/EndpointDslRouteCollector.java     | 58 ++++++++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   | 20 ++++++++
 6 files changed, 120 insertions(+), 16 deletions(-)

diff --git 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index eb22b160277..c2c846edb93 100644
--- 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -42,6 +42,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.config.BeanDefinition;
 import 
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import 
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
 import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
@@ -171,6 +172,7 @@ public class CamelAutoConfiguration {
 
     @Bean
     @ConditionalOnMissingBean(RoutesCollector.class)
+    
@ConditionalOnMissingClass("org.apache.camel.spring.boot.endpointdsl.EndpointDslRouteCollector")
     RoutesCollector routesCollector(ApplicationContext applicationContext) {
         return new SpringBootRoutesCollector(applicationContext);
     }
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 5b32d258ad4..0a29f189e6e 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
@@ -14,22 +14,6 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-#
-# 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.
-#
 
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
 org.apache.camel.spring.boot.CamelAutoConfiguration,\
diff --git a/dsl-starter/camel-endpointdsl-starter/pom.xml 
b/dsl-starter/camel-endpointdsl-starter/pom.xml
index b6c3a2e7edc..66a4e399a3a 100644
--- a/dsl-starter/camel-endpointdsl-starter/pom.xml
+++ b/dsl-starter/camel-endpointdsl-starter/pom.xml
@@ -40,6 +40,11 @@
             <artifactId>spring-boot-starter</artifactId>
             <version>${spring-boot-version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-spring-boot</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-endpointdsl</artifactId>
diff --git 
a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
 
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
new file mode 100644
index 00000000000..2626428843b
--- /dev/null
+++ 
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
@@ -0,0 +1,35 @@
+/*
+ * 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.endpointdsl;
+
+import org.apache.camel.main.RoutesCollector;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Role;
+
+@Configuration(proxyBeanMethods = false)
+@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
+public class EndpointDslAutoConfiguration {
+
+    @Bean
+    RoutesCollector endpointDslRoutesCollector(ApplicationContext 
applicationContext) {
+        return new EndpointDslRouteCollector(applicationContext);
+    }
+
+}
diff --git 
a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
 
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
new file mode 100644
index 00000000000..d5d82c7d7b8
--- /dev/null
+++ 
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
@@ -0,0 +1,58 @@
+/*
+ * 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.endpointdsl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder;
+import org.apache.camel.spring.boot.SpringBootRoutesCollector;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * Enhanced {@link SpringBootRoutesCollector} that supports Endpoint DSL with 
the
+ * lambda style {@link LambdaEndpointRouteBuilder}.
+ */
+public class EndpointDslRouteCollector extends SpringBootRoutesCollector {
+
+    public EndpointDslRouteCollector(ApplicationContext applicationContext) {
+        super(applicationContext);
+    }
+
+    @Override
+    protected Collection<RoutesBuilder> 
collectAdditionalRoutesFromRegistry(CamelContext camelContext, String 
excludePattern, String includePattern) {
+        final List<RoutesBuilder> routes = new ArrayList<>();
+
+        Collection<LambdaEndpointRouteBuilder> lrbs = findByType(camelContext, 
LambdaEndpointRouteBuilder.class);
+        for (LambdaEndpointRouteBuilder lrb : lrbs) {
+            EndpointRouteBuilder rb = new EndpointRouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    lrb.accept(this);
+                }
+            };
+            routes.add(rb);
+        }
+
+        return routes;
+    }
+
+}
diff --git 
a/dsl-starter/camel-endpointdsl-starter/src/main/resources/META-INF/spring.factories
 
b/dsl-starter/camel-endpointdsl-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 00000000000..05ef8619b9a
--- /dev/null
+++ 
b/dsl-starter/camel-endpointdsl-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,20 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.spring.boot.endpointdsl.EndpointDslAutoConfiguration
+

Reply via email to