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/03/23 12:32:21 UTC
(camel) 01/05: CAMEL-20607: camel-core - Using variableReceive should only set result if exchange was process succesfully
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch var-fail
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 951c77f1364285230abd1ba36413f345906b48f6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Mar 23 09:21:21 2024 +0100
CAMEL-20607: camel-core - Using variableReceive should only set result if exchange was process succesfully
---
.../java/org/apache/camel/processor/Enricher.java | 2 +-
.../org/apache/camel/processor/PollEnricher.java | 2 +-
.../camel/processor/SendDynamicProcessor.java | 2 +-
.../org/apache/camel/processor/SendProcessor.java | 4 ++--
.../org/apache/camel/support/ExchangeHelper.java | 22 ++++++++++++++++++++++
5 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Enricher.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Enricher.java
index 5dcabc96fac..97d757a5f99 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Enricher.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Enricher.java
@@ -222,7 +222,7 @@ public class Enricher extends AsyncProcessorSupport implements IdAware, RouteIdA
Exchange aggregatedExchange = aggregationStrategy.aggregate(exchange, resourceExchange);
if (aggregatedExchange != null) {
- if (variableReceive != null) {
+ if (ExchangeHelper.shouldSetVariableResult(exchange, variableReceive)) {
// result should be stored in variable instead of message body
ExchangeHelper.setVariableFromMessageBodyAndHeaders(exchange, variableReceive,
exchange.getMessage());
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java
index d939963dd26..f6cac002f3d 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java
@@ -350,7 +350,7 @@ public class PollEnricher extends AsyncProcessorSupport implements IdAware, Rout
// must catch any exception from aggregation
Exchange aggregatedExchange = aggregationStrategy.aggregate(exchange, resourceExchange);
if (aggregatedExchange != null) {
- if (variableReceive != null) {
+ if (ExchangeHelper.shouldSetVariableResult(exchange, variableReceive)) {
// result should be stored in variable instead of message body
ExchangeHelper.setVariableFromMessageBodyAndHeaders(exchange, variableReceive, exchange.getMessage());
exchange.getMessage().setBody(originalBody);
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java
index d877f180684..94c41c1b107 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java
@@ -237,7 +237,7 @@ public class SendDynamicProcessor extends AsyncProcessorSupport implements IdAwa
ServiceHelper.stopAndShutdownService(endpoint);
}
// result should be stored in variable instead of message body
- if (variableReceive != null) {
+ if (ExchangeHelper.shouldSetVariableResult(exchange, variableReceive)) {
ExchangeHelper.setVariableFromMessageBodyAndHeaders(exchange, variableReceive, exchange.getMessage());
exchange.getMessage().setBody(originalBody);
exchange.getMessage().setHeaders(originalHeaders);
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java
index 04840285980..0f0bde0a265 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java
@@ -179,7 +179,7 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E
ac = doneSync -> {
try {
// result should be stored in variable instead of message body/headers
- if (variableReceive != null) {
+ if (ExchangeHelper.shouldSetVariableResult(exchange, variableReceive)) {
ExchangeHelper.setVariableFromMessageBodyAndHeaders(exchange, variableReceive,
exchange.getMessage());
exchange.getMessage().setBody(originalBody);
@@ -240,7 +240,7 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E
// restore previous MEP
exchange.setPattern(existingPattern);
// result should be stored in variable instead of message body/headers
- if (variableReceive != null) {
+ if (ExchangeHelper.shouldSetVariableResult(exchange, variableReceive)) {
ExchangeHelper.setVariableFromMessageBodyAndHeaders(exchange, variableReceive,
exchange.getMessage());
exchange.getMessage().setBody(originalBody);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
index 2cdf7071450..faa8470376a 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
@@ -1156,6 +1156,28 @@ public final class ExchangeHelper {
}
}
+ /**
+ * Whether the processing of the {@link Exchange} was success and that the result should be stored in variable.
+ *
+ * @param exchange the exchange
+ * @param name the variable name
+ * @return true to call setVariableFromMessageBodyAndHeaders to set the result after-wards
+ */
+ public static boolean shouldSetVariableResult(Exchange exchange, String name) {
+ if (name == null) {
+ return false;
+ }
+ // same logic as in Pipeline/PipelineHelper
+ boolean stop = exchange.isFailed() || exchange.isRollbackOnly() || exchange.isRollbackOnlyLast()
+ || exchange.getExchangeExtension().isErrorHandlerHandledSet()
+ && exchange.getExchangeExtension().isErrorHandlerHandled();
+ if (stop) {
+ return false;
+ }
+ // success
+ return true;
+ }
+
/**
* Gets the variable
*