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 2024/12/26 15:09:05 UTC

(camel) branch main updated: CAMEL-21495: rest-dsl - Mark route as inlined by rest-dsl to avoid duplicate that cause side-effects. (#16653)

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


The following commit(s) were added to refs/heads/main by this push:
     new 7ed4f3ce1e6 CAMEL-21495: rest-dsl - Mark route as inlined by rest-dsl to avoid duplicate that cause side-effects. (#16653)
7ed4f3ce1e6 is described below

commit 7ed4f3ce1e66b44c49cbc37d6b69aaf7bf26567e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Dec 26 16:08:59 2024 +0100

    CAMEL-21495: rest-dsl - Mark route as inlined by rest-dsl to avoid duplicate that cause side-effects. (#16653)
---
 .../main/java/org/apache/camel/impl/DefaultModel.java   |  4 +++-
 .../java/org/apache/camel/model/RouteDefinition.java    | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
index fdb09b8e1cf..03db1eb3f9a 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
@@ -205,7 +205,8 @@ public class DefaultModel implements Model {
             for (RouteDefinition r : allRoutes) {
                 // loop all rest routes
                 FromDefinition from = r.getInput();
-                if (from != null) {
+                if (from != null && !r.isInlined()) {
+                    // only attempt to inline if not already inlined
                     String uri = from.getEndpointUri();
                     if (uri != null && uri.startsWith("rest:")) {
                         // find first EIP in the outputs (skip abstract which are onException/intercept etc)
@@ -267,6 +268,7 @@ public class DefaultModel implements Model {
                                 if (toBeInlined.isErrorHandlerFactorySet()) {
                                     r.setErrorHandler(toBeInlined.getErrorHandler());
                                 }
+                                r.markInlined();
                             }
                         }
                     }
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
index fd684283697..a388b1ba90b 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -62,6 +62,7 @@ import org.apache.camel.spi.RoutePolicy;
 public class RouteDefinition extends OutputDefinition<RouteDefinition>
         implements NamedRoute, PreconditionContainer, ResourceAware {
     private final AtomicBoolean prepared = new AtomicBoolean();
+    private final AtomicBoolean inlined = new AtomicBoolean();
     private FromDefinition input;
     private String routeConfigurationId;
     private transient Set<String> appliedRouteConfigurationIds;
@@ -147,6 +148,22 @@ public class RouteDefinition extends OutputDefinition<RouteDefinition>
         prepared.set(false);
     }
 
+    /**
+     * Check if the route has been inlined by rest-dsl
+     *
+     * @return whether the route has been inlined by rest-dsl or not
+     */
+    public boolean isInlined() {
+        return inlined.get();
+    }
+
+    /**
+     * Marks the route definition as inlined by rest-dsl
+     */
+    public void markInlined() {
+        inlined.set(true);
+    }
+
     /**
      * Reset internal state before preparing route
      */