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

davsclaus pushed a commit to branch templatedroutes
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0fbb0d62f8eb68aeca0cfda898f0b82804402d78
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 27 14:13:56 2022 +0100

    CAMEL-18764: camel-core - templatedRoute builder from Java cannot use 
templates from other DSLs
---
 core/camel-api/src/main/java/org/apache/camel/CamelContext.java  | 9 +++++++++
 core/camel-api/src/main/java/org/apache/camel/RoutesBuilder.java | 8 ++++++++
 .../java/org/apache/camel/impl/engine/AbstractCamelContext.java  | 8 ++++++++
 .../java/org/apache/camel/impl/lw/LightweightCamelContext.java   | 5 +++++
 .../org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java | 5 +++++
 .../src/main/java/org/apache/camel/builder/RouteBuilder.java     | 6 +++++-
 .../src/main/java/org/apache/camel/main/RoutesConfigurer.java    | 5 +++++
 7 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java 
b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
index ecd6716401f..883b31780c5 100644
--- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
+++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
@@ -579,6 +579,15 @@ public interface CamelContext extends 
CamelContextLifecycle, RuntimeConfiguratio
      */
     void addRoutes(RoutesBuilder builder) throws Exception;
 
+    /**
+     * Adds the templated route from the routes builder.
+     * For example in Java DSL you can use {@link 
org.apache.camel.builder.TemplatedRouteBuilder}.
+     *
+     * @param  builder   the builder which has templated routes
+     * @throws Exception if the routes could not be created for whatever reason
+     */
+    void addTemplatedRoutes(RoutesBuilder builder) throws Exception;
+
     /**
      * Adds the routes configurations (global configuration for all routes) 
from the routes builder.
      *
diff --git a/core/camel-api/src/main/java/org/apache/camel/RoutesBuilder.java 
b/core/camel-api/src/main/java/org/apache/camel/RoutesBuilder.java
index 39ee3bf9f1c..a7bd5273d17 100644
--- a/core/camel-api/src/main/java/org/apache/camel/RoutesBuilder.java
+++ b/core/camel-api/src/main/java/org/apache/camel/RoutesBuilder.java
@@ -36,6 +36,14 @@ public interface RoutesBuilder {
      */
     void addRoutesToCamelContext(CamelContext context) throws Exception;
 
+    /**
+     * Adds the templated routes from this Route Builder to the CamelContext.
+     *
+     * @param  context   the Camel context
+     * @throws Exception is thrown if initialization of routes failed
+     */
+    void addTemplatedRoutesToCamelContext(CamelContext context) throws 
Exception;
+
     /**
      * Adds or updates the routes from this Route Builder to the CamelContext.
      *
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index d085b2b1798..520272ad239 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -1202,6 +1202,14 @@ public abstract class AbstractCamelContext extends 
BaseService
         }
     }
 
+    @Override
+    public void addTemplatedRoutes(RoutesBuilder builder) throws Exception {
+        try (LifecycleHelper helper = new LifecycleHelper()) {
+            build();
+            LOG.debug("Adding templated routes from builder: {}", builder);
+            
builder.addTemplatedRoutesToCamelContext(AbstractCamelContext.this);
+        }
+    }
     @Override
     public void addRoutesConfigurations(RouteConfigurationsBuilder builder) 
throws Exception {
         try (LifecycleHelper helper = new LifecycleHelper()) {
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
index 53a5f2f2116..0800e42775e 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
@@ -576,6 +576,11 @@ public class LightweightCamelContext implements 
ExtendedCamelContext, CatalogCam
         delegate.addRoutes(builder);
     }
 
+    @Override
+    public void addTemplatedRoutes(RoutesBuilder builder) throws Exception {
+        delegate.addTemplatedRoutes(builder);
+    }
+
     @Override
     public void addRoutesConfigurations(RouteConfigurationsBuilder builder) 
throws Exception {
         delegate.addRoutesConfigurations(builder);
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
index e4f996d30ed..aec0eda6796 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
@@ -2043,6 +2043,11 @@ public class LightweightRuntimeCamelContext implements 
ExtendedCamelContext, Cat
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public void addTemplatedRoutes(RoutesBuilder builder) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
     @Override
     public void addRoutesConfigurations(RouteConfigurationsBuilder builder) 
throws Exception {
         throw new UnsupportedOperationException();
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 9aa0025548e..a646aff17b9 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -605,7 +605,6 @@ public abstract class RouteBuilder extends BuilderSupport 
implements RoutesBuild
         populateTransformers();
         populateValidators();
         populateRouteTemplates();
-        populateTemplatedRoutes();
 
         // ensure routes are prepared before being populated
         for (RouteDefinition route : routeCollection.getRoutes()) {
@@ -618,6 +617,11 @@ public abstract class RouteBuilder extends BuilderSupport 
implements RoutesBuild
         }
     }
 
+    @Override
+    public void addTemplatedRoutesToCamelContext(CamelContext context) throws 
Exception {
+        populateTemplatedRoutes();
+    }
+
     @Override
     public Set<String> updateRoutesToCamelContext(CamelContext context) throws 
Exception {
         Set<String> answer = new LinkedHashSet<>();
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 84ba9a9471f..de7ea91ddcc 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
@@ -236,6 +236,11 @@ public class RoutesConfigurer {
             LOG.debug("Adding routes into CamelContext from RoutesBuilder: 
{}", builder);
             camelContext.addRoutes(builder);
         }
+        // then add templated routes last
+        for (RoutesBuilder builder : routes) {
+            LOG.debug("Adding templated routes into CamelContext from 
RoutesBuilder: {}", builder);
+            camelContext.addTemplatedRoutes(builder);
+        }
     }
 
     /**

Reply via email to