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 2020/03/05 11:03:25 UTC
[camel] branch master updated: CAMEL-14659: camel-core - Thread
stuck if exception is thrown in handle(Predicate) with onException
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 5743ff3 CAMEL-14659: camel-core - Thread stuck if exception is thrown in handle(Predicate) with onException
5743ff3 is described below
commit 5743ff3a05039dfe8db09f13a9de562b410d95eb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 5 12:02:58 2020 +0100
CAMEL-14659: camel-core - Thread stuck if exception is thrown in handle(Predicate) with onException
---
.../errorhandler/RedeliveryErrorHandler.java | 10 ++++
.../OnExceptionHandledThrowsExceptionTest.java | 54 ++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index 5a62994..637747d 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -612,6 +612,16 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
return;
}
+ try {
+ doRun();
+ } catch (Throwable e) {
+ // unexpected exception during running so break out
+ exchange.setException(e);
+ callback.done(false);
+ }
+ }
+
+ private void doRun() throws Exception {
// did previous processing cause an exception?
if (exchange.getException() != null) {
handleException();
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledThrowsExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledThrowsExceptionTest.java
new file mode 100644
index 0000000..14ecfe9
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledThrowsExceptionTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.onexception;
+
+import java.io.IOException;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class OnExceptionHandledThrowsExceptionTest extends ContextTestSupport {
+
+ @Test
+ public void testHandled() throws Exception {
+ getMockEndpoint("mock:handled").expectedMessageCount(0);
+
+ try {
+ template.sendBody("direct:start", "Hello World");
+ fail("Should have thrown exception");
+ } catch (Exception e) {
+ IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Another Forced", iae.getMessage());
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ onException(IOException.class)
+ .handled(e -> { throw new IllegalArgumentException("Another Forced");}).to("log:foo?showAll=true").to("mock:handled");
+
+ from("direct:start").throwException(new IOException("Forced"));
+ }
+ };
+ }
+}