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:31:09 UTC
[camel] branch camel-3.x 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 camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push:
new 9046cf59fbb CAMEL-18874: When possible, pass the exchange to the exception handler
9046cf59fbb is described below
commit 9046cf59fbb76f50052136f0bea8869322412d98
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 1b7b8adf562..312e4ddcb5f 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
@@ -407,11 +407,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;
}
@@ -503,7 +503,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;
@@ -548,7 +548,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 16ba0651eaf..54aec9b03be 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
@@ -1449,6 +1449,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 d3d97b3fa8a..a64bb0ca48a 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
@@ -259,6 +259,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;