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/08/03 17:45:20 UTC
[camel] branch main updated: exception in onCompletionProcessor should be suppressed, other than be lost (#10944)
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 e4a15fa414f exception in onCompletionProcessor should be suppressed, other than be lost (#10944)
e4a15fa414f is described below
commit e4a15fa414f3250431bc4ffced4ecfc72df59e5a
Author: EvanMi <43...@users.noreply.github.com>
AuthorDate: Fri Aug 4 01:45:14 2023 +0800
exception in onCompletionProcessor should be suppressed, other than be lost (#10944)
CAMEL-19688: exception in onCompletionProcessor should be suppressed, other than be lost
Co-authored-by: mipengcheng <mi...@jd.com>
---
.../camel/processor/OnCompletionProcessor.java | 4 ++
...nModeBeforeConsumerExceptionSuppressedTest.java | 62 ++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
index 0c3abe1f9cf..cfdd5d6b5db 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
@@ -201,6 +201,10 @@ public class OnCompletionProcessor extends AsyncProcessorSupport implements Trac
exchange.setRollbackOnlyLast(rollbackOnlyLast);
exchange.getExchangeExtension().setRedeliveryExhausted(exhausted);
if (cause != null) {
+ // if there is any exception in onCompletionProcessor, the exception should be suppressed
+ if (exchange.isFailed()) {
+ cause.addSuppressed(exchange.getException());
+ }
exchange.setException(cause);
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/OnCompletionModeBeforeConsumerExceptionSuppressedTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/OnCompletionModeBeforeConsumerExceptionSuppressedTest.java
new file mode 100644
index 00000000000..69f821f0f7c
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/OnCompletionModeBeforeConsumerExceptionSuppressedTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class OnCompletionModeBeforeConsumerExceptionSuppressedTest extends ContextTestSupport {
+
+ @Test
+ public void testOnCompletionModeBeforeConsumerExceptionSuppressed() {
+ Exchange out = template.request("direct:foo", exchange -> exchange.getIn().setBody("Camel"));
+ Exception fooException = out.getException();
+ assertIsInstanceOf(FooException.class, fooException);
+ Throwable[] suppressed = fooException.getSuppressed();
+ assertEquals(suppressed.length, 1);
+ assertIsInstanceOf(SuppressedException.class, suppressed[0]);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:foo")
+ .process(exchange -> {
+ throw new FooException();
+ })
+ .onCompletion()
+ .modeBeforeConsumer()
+ .process(exchange -> {
+ throw new SuppressedException();
+ })
+ .end();
+ }
+ };
+ }
+
+ public static class FooException extends RuntimeException {
+ }
+
+ public static class SuppressedException extends RuntimeException {
+ }
+}