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 2022/01/18 09:18:51 UTC
[camel] branch main updated: CAMEL-17504: Consumer with bridgeErrorHandler=true does not work correctly. Thanks to Benjamin Graf for test case.
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 714f512 CAMEL-17504: Consumer with bridgeErrorHandler=true does not work correctly. Thanks to Benjamin Graf for test case.
714f512 is described below
commit 714f512a5ede9be71aeb8f4d3a814357a15203ff
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jan 18 10:04:57 2022 +0100
CAMEL-17504: Consumer with bridgeErrorHandler=true does not work correctly. Thanks to Benjamin Graf for test case.
---
.../org/apache/camel/ExchangeConstantProvider.java | 5 ++-
.../src/main/java/org/apache/camel/Exchange.java | 3 +-
.../java/org/apache/camel/ExchangePropertyKey.java | 3 ++
.../errorhandler/RedeliveryErrorHandler.java | 8 ++--
.../component/file/FileBridgeErrorHandlerTest.java | 48 ++++++++++++++++++++++
.../BridgeExceptionHandlerToErrorHandler.java | 3 ++
.../org/apache/camel/support/ExchangeHelper.java | 10 +++++
7 files changed, 74 insertions(+), 6 deletions(-)
diff --git a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
index 6f9b37b..fed0d14 100644
--- a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
+++ b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
@@ -11,7 +11,7 @@ public class ExchangeConstantProvider {
private static final Map<String, String> MAP;
static {
- Map<String, String> map = new HashMap<>(151);
+ Map<String, String> map = new HashMap<>(152);
map.put("ACCEPT_CONTENT_TYPE", "CamelAcceptContentType");
map.put("AGGREGATED_COLLECTION_GUARD", "CamelAggregatedCollectionGuard");
map.put("AGGREGATED_COMPLETED_BY", "CamelAggregatedCompletedBy");
@@ -47,7 +47,8 @@ public class ExchangeConstantProvider {
map.put("DISABLE_HTTP_STREAM_CACHE", "CamelDisableHttpStreamCache");
map.put("DOCUMENT_BUILDER_FACTORY", "CamelDocumentBuilderFactory");
map.put("DUPLICATE_MESSAGE", "CamelDuplicateMessage");
- map.put("ERRORHANDLER_CIRCUIT_DETECTED", "CamelFErrorHandlerCircuitDetected");
+ map.put("ERRORHANDLER_BRIDGE", "CamelErrorHandlerBridge");
+ map.put("ERRORHANDLER_CIRCUIT_DETECTED", "CamelErrorHandlerCircuitDetected");
map.put("ERRORHANDLER_HANDLED", "CamelErrorHandlerHandled");
map.put("EVALUATE_EXPRESSION_RESULT", "CamelEvaluateExpressionResult");
map.put("EXCEPTION_CAUGHT", "CamelExceptionCaught");
diff --git a/core/camel-api/src/main/java/org/apache/camel/Exchange.java b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
index 52d4707..b7b7a1f 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Exchange.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
@@ -111,7 +111,8 @@ public interface Exchange {
String EXCEPTION_CAUGHT = "CamelExceptionCaught";
String EXCEPTION_HANDLED = "CamelExceptionHandled";
String EVALUATE_EXPRESSION_RESULT = "CamelEvaluateExpressionResult";
- String ERRORHANDLER_CIRCUIT_DETECTED = "CamelFErrorHandlerCircuitDetected";
+ String ERRORHANDLER_BRIDGE = "CamelErrorHandlerBridge";
+ String ERRORHANDLER_CIRCUIT_DETECTED = "CamelErrorHandlerCircuitDetected";
@Deprecated
String ERRORHANDLER_HANDLED = "CamelErrorHandlerHandled";
@Deprecated
diff --git a/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
index f417303..bbad968 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
@@ -42,6 +42,7 @@ public enum ExchangePropertyKey {
CLAIM_CHECK_REPOSITORY(Exchange.CLAIM_CHECK_REPOSITORY),
CORRELATION_ID(Exchange.CORRELATION_ID),
DUPLICATE_MESSAGE(Exchange.DUPLICATE_MESSAGE),
+ ERRORHANDLER_BRIDGE(Exchange.ERRORHANDLER_BRIDGE),
ERRORHANDLER_CIRCUIT_DETECTED(Exchange.ERRORHANDLER_CIRCUIT_DETECTED),
EVALUATE_EXPRESSION_RESULT(Exchange.EVALUATE_EXPRESSION_RESULT),
EXCEPTION_CAUGHT(Exchange.EXCEPTION_CAUGHT),
@@ -123,6 +124,8 @@ public enum ExchangePropertyKey {
return CORRELATION_ID;
case Exchange.DUPLICATE_MESSAGE:
return DUPLICATE_MESSAGE;
+ case Exchange.ERRORHANDLER_BRIDGE:
+ return ERRORHANDLER_BRIDGE;
case Exchange.ERRORHANDLER_CIRCUIT_DETECTED:
return ERRORHANDLER_CIRCUIT_DETECTED;
case Exchange.EVALUATE_EXPRESSION_RESULT:
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 d418a6a..5e01771 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
@@ -451,10 +451,12 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
// and it has not been handled by the failure processor before
// or not exhausted
boolean failure = exchange.getException() != null
- && !ExchangeHelper.isFailureHandled(exchange)
- && !exchange.isRedeliveryExhausted();
+ && !exchange.isRedeliveryExhausted()
+ && !ExchangeHelper.isFailureHandled(exchange);
+ // error handled bridged
+ boolean bridge = ExchangeHelper.isErrorHandlerBridge(exchange);
- if (failure) {
+ if (failure || bridge) {
// previous processing cause an exception
handleException();
onExceptionOccurred();
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileBridgeErrorHandlerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileBridgeErrorHandlerTest.java
new file mode 100644
index 0000000..60ad734
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileBridgeErrorHandlerTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+public class FileBridgeErrorHandlerTest extends ContextTestSupport {
+
+ @Test
+ public void testBridgeErrorHandler() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:error").expectedMinimumMessageCount(1);
+ getMockEndpoint("mock:error").allMessages().exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ onException(Exception.class).handled(true).to("mock:error");
+
+ from("file://target/dummy?bridgeErrorHandler=true&autoCreate=false&directoryMustExist=true")
+ .log("${body}")
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/BridgeExceptionHandlerToErrorHandler.java b/core/camel-support/src/main/java/org/apache/camel/support/BridgeExceptionHandlerToErrorHandler.java
index b2408dd..8e2094e 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/BridgeExceptionHandlerToErrorHandler.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/BridgeExceptionHandlerToErrorHandler.java
@@ -17,6 +17,7 @@
package org.apache.camel.support;
import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePropertyKey;
import org.apache.camel.ExtendedExchange;
import org.apache.camel.Processor;
import org.apache.camel.spi.ExceptionHandler;
@@ -66,6 +67,8 @@ public class BridgeExceptionHandlerToErrorHandler implements ExceptionHandler {
exchange.setException(exception);
// and the message
exchange.getIn().setBody(message);
+ // mark as bridged
+ exchange.setProperty(ExchangePropertyKey.ERRORHANDLER_BRIDGE, true);
// and mark as redelivery exhausted as we cannot do redeliveries
exchange.adapt(ExtendedExchange.class).setRedeliveryExhausted(true);
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 b3bbcb5..89c1c76 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
@@ -613,6 +613,16 @@ public final class ExchangeHelper {
}
/**
+ * Checks whether the exchange has been error handler bridged
+ *
+ * @param exchange the exchange
+ * @return <tt>true</tt> if error handler bridged, <tt>false</tt> otherwise
+ */
+ public static boolean isErrorHandlerBridge(Exchange exchange) {
+ return exchange.getProperty(ExchangePropertyKey.ERRORHANDLER_BRIDGE, false, Boolean.class);
+ }
+
+ /**
* Checks whether the exchange {@link UnitOfWork} is exhausted
*
* @param exchange the exchange