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 2023/05/24 05:30:52 UTC

[camel] branch main updated: CAMEL-18874: When possible, pass the exchange to the exception handler

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 ccae92eda8c CAMEL-18874: When possible, pass the exchange to the exception handler
ccae92eda8c is described below

commit ccae92eda8ce089c6c5c0596e255fbeec17cad73
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed May 24 07:30:33 2023 +0200

    CAMEL-18874: When possible, pass the exchange to the exception handler
---
 .../org/apache/camel/component/file/GenericFileConsumer.java |  8 ++++----
 .../main/java/org/apache/camel/processor/Resequencer.java    |  5 +++--
 .../apache/camel/processor/aggregate/AggregateProcessor.java |  1 +
 .../main/java/org/apache/camel/support/DefaultConsumer.java  | 12 ++++++++++++
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
index ef3c28a2d71..8812150e8de 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
@@ -406,11 +406,11 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
             }
             if (beginCause != null) {
                 String msg = endpoint + " cannot begin processing file: " + file + " due to: " + beginCause.getMessage();
-                handleException(msg, beginCause);
+                handleException(msg, exchange, beginCause);
             }
             if (abortCause != null) {
                 String msg2 = endpoint + " cannot abort processing file: " + file + " due to: " + abortCause.getMessage();
-                handleException(msg2, abortCause);
+                handleException(msg2, exchange, abortCause);
             }
             return false;
         }
@@ -502,7 +502,7 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
             endpoint.getInProgressRepository().remove(absoluteFileName);
 
             String msg = "Error processing file " + file + " due to " + e.getMessage();
-            handleException(msg, e);
+            handleException(msg, exchange, e);
         }
 
         return true;
@@ -547,7 +547,7 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
             LOG.debug("{} error custom processing: {} due to: {}. This exception will be ignored.",
                     endpoint, file, e.getMessage(), e);
 
-            handleException(e);
+            handleException("Error during custom processing", exchange, e);
         } finally {
             // always remove file from the in progress list as its no longer in
             // progress
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Resequencer.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Resequencer.java
index c1ad5e99e67..1c2db9b6ca1 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Resequencer.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Resequencer.java
@@ -322,7 +322,8 @@ public class Resequencer extends AsyncProcessorSupport implements Navigate<Proce
 
     protected void postProcess(Exchange exchange) {
         if (exchange.getException() != null) {
-            getExceptionHandler().handleException("Error processing aggregated exchange: " + exchange, exchange.getException());
+            getExceptionHandler().handleException("Error processing aggregated exchange: " + exchange, exchange,
+                    exchange.getException());
         }
     }
 
@@ -512,7 +513,7 @@ public class Resequencer extends AsyncProcessorSupport implements Navigate<Proce
                     } catch (Exception t) {
                         e.setException(t);
                     } catch (Throwable t) {
-                        getExceptionHandler().handleException(t);
+                        getExceptionHandler().handleException("Error adding exchange", e, t);
                     }
                     if (exchangeId != null && exchangeId.equals(e.getExchangeId())) {
                         // this batch is complete so stop draining
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
index 6cb8cf0db21..39c3f85d872 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
@@ -1447,6 +1447,7 @@ public class AggregateProcessor extends AsyncProcessorSupport
                                         getExceptionHandler()
                                                 .handleException("Failed to move recovered Exchange to dead letter channel: "
                                                                  + recoverable.getDeadLetterUri(),
+                                                        exchange,
                                                         exchange.getException());
                                     } else {
                                         // it was ok, so confirm after it has been moved to dead letter channel, so we wont recover it again
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
index 0f8a8e70f14..06534a47bfc 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
@@ -256,6 +256,18 @@ public class DefaultConsumer extends ServiceSupport implements Consumer, RouteAw
         getExceptionHandler().handleException(message, newt);
     }
 
+    /**
+     * Handles the given exception using the {@link #getExceptionHandler()}
+     *
+     * @param message  additional message about the exception
+     * @param exchange exchange which cause the exception
+     * @param t        the exception to handle
+     */
+    protected void handleException(String message, Exchange exchange, Throwable t) {
+        Throwable newt = (t == null) ? new IllegalArgumentException("Handling [null] exception") : t;
+        getExceptionHandler().handleException(message, exchange, newt);
+    }
+
     private static final class DefaultConsumerCallback implements AsyncCallback {
 
         private final DefaultConsumer consumer;