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 2021/11/05 12:36:05 UTC
[camel] branch main updated: CAMEL-17166: http components using
muteException should return empty message body instead of the text
Exception.
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 fc43e912 CAMEL-17166: http components using muteException should return empty message body instead of the text Exception.
fc43e912 is described below
commit fc43e9123141e29c40b5ea061bf12660f16e8108
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Nov 5 13:35:23 2021 +0100
CAMEL-17166: http components using muteException should return empty message body instead of the text Exception.
---
.../org/apache/camel/http/common/DefaultHttpBinding.java | 2 +-
.../component/netty/http/DefaultNettyHttpBinding.java | 5 ++---
.../component/netty/http/NettyHttpMuteExceptionTest.java | 2 +-
.../component/servlet/ServletCamelRouterTestSupport.java | 16 ++++++++++------
.../component/servlet/ServletMuteExceptionTest.java | 4 ++--
.../camel/component/undertow/UndertowConsumer.java | 3 +--
.../component/undertow/UndertowMuteExceptionTest.java | 4 ++--
.../undertow/rest/RestUndertowContentTypeTest.java | 2 +-
.../modules/ROOT/pages/camel-3x-upgrade-guide-3_13.adoc | 7 +++++++
9 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
index 76bfa7a..9fa5625 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
@@ -373,8 +373,8 @@ public class DefaultHttpBinding implements HttpBinding {
response.getWriter().write("Timeout error");
} else if (isMuteException()) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ response.setContentLength(0);
response.setContentType("text/plain");
- response.getWriter().write("Exception");
} else {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
index aa5e05d..7d8b373 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
@@ -430,9 +430,8 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable {
// and mark the exception as failure handled, as we handled it by returning it as the response
ExchangeHelper.setFailureHandled(message.getExchange());
} else if (cause != null && configuration.isMuteException()) {
-
- // the body should hide the stacktrace (muteException enabled)
- body = NettyConverter.toByteBuffer("Exception".getBytes());
+ // empty body
+ body = NettyConverter.toByteBuffer("".getBytes());
// force content type to be text/plain
message.setHeader(Exchange.CONTENT_TYPE, "text/plain");
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpMuteExceptionTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpMuteExceptionTest.java
index b72792d..1e67a38 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpMuteExceptionTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpMuteExceptionTest.java
@@ -38,7 +38,7 @@ public class NettyHttpMuteExceptionTest extends BaseNettyTest {
try (CloseableHttpResponse response = client.execute(get)) {
String body = EntityUtils.toString(response.getEntity(), "UTF-8");
assertNotNull(body);
- assertEquals("Exception", body);
+ assertEquals("", body);
assertEquals(500, response.getStatusLine().getStatusCode());
}
}
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletCamelRouterTestSupport.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletCamelRouterTestSupport.java
index 5e6b41c..d1da5d6 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletCamelRouterTestSupport.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletCamelRouterTestSupport.java
@@ -210,12 +210,16 @@ public class ServletCamelRouterTestSupport extends CamelTestSupport {
public String getText(Charset charset) throws IOException {
if (text == null) {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- IOHelper.copy(con.getInputStream(), baos);
- text = baos.toString(charset.name());
- } catch (IOException e) {
- text = "Exception";
+ if (con.getContentLength() != 0) {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOHelper.copy(con.getInputStream(), baos);
+ text = baos.toString(charset.name());
+ } catch (IOException e) {
+ text = e.getMessage();
+ }
+ } else {
+ text = "";
}
}
return text;
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletMuteExceptionTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletMuteExceptionTest.java
index 5d0a2d4..a613e7a 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletMuteExceptionTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletMuteExceptionTest.java
@@ -34,7 +34,7 @@ public class ServletMuteExceptionTest extends ServletCamelRouterTestSupport {
assertEquals(500, response.getResponseCode());
assertEquals("text/plain", response.getContentType());
- assertEquals("Exception", response.getText());
+ assertEquals("", response.getText());
}
@Test
@@ -46,7 +46,7 @@ public class ServletMuteExceptionTest extends ServletCamelRouterTestSupport {
assertEquals(500, response.getResponseCode());
assertEquals("text/plain", response.getContentType());
- assertEquals("Exception", response.getText());
+ assertEquals("", response.getText());
}
@Override
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index f3d230c..89f1ffc 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -246,13 +246,12 @@ public class UndertowConsumer extends DefaultConsumer implements HttpHandler, Su
Object body = getResponseBody(httpExchange, camelExchange);
if (body == null) {
- String message = httpExchange.getStatusCode() == 500 ? "Exception" : "No response available";
LOG.trace("No payload to send as reply for exchange: {}", camelExchange);
// respect Content-Type assigned from HttpBinding if any
String contentType = camelExchange.getIn().getHeader(Exchange.CONTENT_TYPE,
MimeMappings.DEFAULT_MIME_MAPPINGS.get("txt"), String.class);
httpExchange.getResponseHeaders().put(ExchangeHeaders.CONTENT_TYPE, contentType);
- httpExchange.getResponseSender().send(message);
+ httpExchange.getResponseSender().send(""); // empty body
return;
}
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java
index fff5d61..8d7478c 100644
--- a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java
@@ -39,7 +39,7 @@ public class UndertowMuteExceptionTest extends BaseUndertowTest {
String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
assertNotNull(responseString);
- assertEquals("Exception", responseString);
+ assertEquals("", responseString);
assertEquals(500, response.getStatusLine().getStatusCode());
client.close();
@@ -56,7 +56,7 @@ public class UndertowMuteExceptionTest extends BaseUndertowTest {
String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
assertNotNull(responseString);
- assertEquals("Exception", responseString);
+ assertEquals("", responseString);
assertEquals(500, response.getStatusLine().getStatusCode());
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowContentTypeTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowContentTypeTest.java
index a248872..0b5aeca 100644
--- a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowContentTypeTest.java
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowContentTypeTest.java
@@ -58,7 +58,7 @@ public class RestUndertowContentTypeTest extends BaseUndertowTest {
HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, ex.getCause());
assertEquals(415, cause.getStatusCode());
- assertEquals("No response available", cause.getResponseBody());
+ assertEquals("", cause.getResponseBody());
}
@Test
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_13.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_13.adoc
index c66979e..76cb6d5 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_13.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_13.adoc
@@ -122,3 +122,10 @@ The `triggerStartDelay` parameter supports negative value to shift trigger start
=== camel-aws2-sqs
Since the maximum number of attributes per SQS message is 10, we are limiting the number of headers to be converted to attributes to 10.
+
+=== When using muteException
+
+HTTP based components that are using `muteException=true` will return an empty message body,
+instead of the text `Exception`.
+
+This applies to camel-jetty, camel-undertow, camel-servlet, camel-netty-http