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 659ce166214 CAMEL-21957: camel-core - Error handler should store 
failure route id eager so onRedelivery/onExceptionOccurred processors have 
access
659ce166214 is described below

commit 659ce1662140ca6871bb584c113d542fe337286e
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Apr 11 18:12:59 2025 +0200

    CAMEL-21957: camel-core - Error handler should store failure route id eager 
so onRedelivery/onExceptionOccurred processors have access
---
 .../onexception/OnExceptionOccurredProcessorTest.xml         |  2 +-
 .../camel/processor/errorhandler/RedeliveryErrorHandler.java | 12 ++++++++++++
 .../camel/processor/DeadLetterChannelOnRedeliveryTest.java   |  7 ++++++-
 .../onexception/OnExceptionOccurredProcessorTest.java        |  6 ++++--
 4 files changed, 23 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/onexception/OnExceptionOccurredProcessorTest.xml
 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/onexception/OnExceptionOccurredProcessorTest.xml
index 275d9b3a69b..45d7d63f2ca 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/onexception/OnExceptionOccurredProcessorTest.xml
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/onexception/OnExceptionOccurredProcessorTest.xml
@@ -36,7 +36,7 @@
       <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="0"/>
     </errorHandler>
 
-    <route>
+    <route id="foo">
       <from uri="direct:start"/>
       <throwException ref="forced"/>
     </route>
diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index 66f2af4edb4..6695e2ab1a8 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -502,6 +502,12 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport
 
             // store the original caused exception in a property, so we can 
restore it later
             exchange.setProperty(ExchangePropertyKey.EXCEPTION_CAUGHT, e);
+
+            // store where the exception happened
+            Route rc = ExchangeHelper.getRoute(exchange);
+            if (rc != null) {
+                exchange.setProperty(ExchangePropertyKey.FAILURE_ROUTE_ID, 
rc.getRouteId());
+            }
         }
 
         /**
@@ -1049,6 +1055,12 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport
             }
 
             redeliveryCounter = incrementRedeliveryCounter(exchange);
+
+            // store where the exception happened
+            Route rc = ExchangeHelper.getRoute(exchange);
+            if (rc != null) {
+                exchange.setProperty(ExchangePropertyKey.FAILURE_ROUTE_ID, 
rc.getRouteId());
+            }
         }
 
         /**
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java
index c593e4726d2..9fec14fd455 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java
@@ -75,7 +75,7 @@ public class DeadLetterChannelOnRedeliveryTest extends 
ContextTestSupport {
                         .redeliveryDelay(0L));
                 // END SNIPPET: e1
 
-                from("direct:start").process(new Processor() {
+                from("direct:start").routeId("myRoute").process(new 
Processor() {
                     public void process(Exchange exchange) {
                         // force some error so Camel will do redelivery
                         if (++counter <= 3) {
@@ -108,7 +108,12 @@ public class DeadLetterChannelOnRedeliveryTest extends 
ContextTestSupport {
             // the maximum redelivery was set to 5
             int max = 
exchange.getIn().getHeader(Exchange.REDELIVERY_MAX_COUNTER, Integer.class);
             assertEquals(5, max);
+
+            // should be happening inside myRoute
+            String rid = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, 
String.class);
+            assertEquals("myRoute", rid);
         }
+
     }
     // END SNIPPET: e2
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionOccurredProcessorTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionOccurredProcessorTest.java
index 4b195717220..6f798d948b3 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionOccurredProcessorTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionOccurredProcessorTest.java
@@ -57,9 +57,9 @@ public class OnExceptionOccurredProcessorTest extends 
ContextTestSupport {
                 
errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(3).redeliveryDelay(0)
                         .onExceptionOccurred(myProcessor));
 
-                from("direct:start").to("log:a").to("direct:foo").to("log:b");
+                
from("direct:start").routeId("start").to("log:a").to("direct:foo").to("log:b");
 
-                from("direct:foo").throwException(new 
IllegalArgumentException("Forced"));
+                from("direct:foo").routeId("foo").throwException(new 
IllegalArgumentException("Forced"));
             }
         };
     }
@@ -71,6 +71,8 @@ public class OnExceptionOccurredProcessorTest extends 
ContextTestSupport {
         @Override
         public void process(Exchange exchange) {
             invoked++;
+            String rid = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, 
String.class);
+            assertEquals("foo", rid);
         }
 
         public int getInvoked() {

Reply via email to