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 2017/11/22 18:18:31 UTC
[camel] branch camel-2.20.x updated: CAMEL-12021: Fixed producer
template to not lose original thrown exception if expected to convert
response to another type and that also fails with a new exception. Thanks
to Thomas Papke for unit test.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.20.x by this push:
new 065ebe2 CAMEL-12021: Fixed producer template to not lose original thrown exception if expected to convert response to another type and that also fails with a new exception. Thanks to Thomas Papke for unit test.
065ebe2 is described below
commit 065ebe2cd458956c0fac96b15c07ed0e6ece3e9a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Nov 22 19:17:48 2017 +0100
CAMEL-12021: Fixed producer template to not lose original thrown exception if expected to convert response to another type and that also fails with a new exception. Thanks to Thomas Papke for unit test.
---
.../camel/processor/ConvertBodyProcessor.java | 7 +++++++
.../camel/impl/DefaultProducerTemplateTest.java | 22 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
index 41a94a7..6c0a079 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/ConvertBodyProcessor.java
@@ -80,6 +80,13 @@ public class ConvertBodyProcessor extends ServiceSupport implements AsyncProcess
return true;
}
+ if (exchange.getException() != null) {
+ // do not convert if an exception has been thrown as if we attempt to convert and it also fails with a new
+ // exception then it will override the existing exception
+ callback.done(true);
+ return true;
+ }
+
if (charset != null) {
// override existing charset with configured charset as that is what the user
// have explicit configured and expects to be used
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java b/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
index 6dc3c8e..29793a6 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
@@ -84,11 +84,27 @@ public class DefaultProducerTemplateTest extends ContextTestSupport {
assertMockEndpointsSatisfied();
}
+ public void testExceptionOnRequestBodyWithResponseType() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(0);
+
+ try {
+ template.requestBody("direct:exception", "Hello World", Integer.class);
+ fail("Should have thrown RuntimeCamelException");
+ } catch (RuntimeCamelException e) {
+ assertTrue(e.getCause() instanceof IllegalArgumentException);
+ assertEquals("Forced exception by unit test", e.getCause().getMessage());
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
public void testExceptionUsingProcessor() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
Exchange out = template.send("direct:exception", new Processor() {
+ @Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
}
@@ -134,6 +150,7 @@ public class DefaultProducerTemplateTest extends ContextTestSupport {
mock.expectedMessageCount(0);
Exchange out = template.request("direct:exception", new Processor() {
+ @Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
}
@@ -223,23 +240,27 @@ public class DefaultProducerTemplateTest extends ContextTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
+ @Override
public void configure() throws Exception {
// for faster unit test
errorHandler(noErrorHandler());
from("direct:in").process(new Processor() {
+ @Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Bye World");
}
}).to("mock:result");
from("direct:out").process(new Processor() {
+ @Override
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody("Bye Bye World");
}
}).to("mock:result");
from("direct:fault").process(new Processor() {
+ @Override
public void process(Exchange exchange) throws Exception {
exchange.getOut().setFault(true);
exchange.getOut().setBody("Faulty World");
@@ -247,6 +268,7 @@ public class DefaultProducerTemplateTest extends ContextTestSupport {
}).to("mock:result");
from("direct:exception").process(new Processor() {
+ @Override
public void process(Exchange exchange) throws Exception {
throw new IllegalArgumentException("Forced exception by unit test");
}
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].