This is an automated email from the ASF dual-hosted git repository. tsato pushed a commit to branch camel-2.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit eb48ec1d4761bc56cc9b8a7ae81bdf9a2e6f14cf Author: Tadayoshi Sato <[email protected]> AuthorDate: Thu Sep 12 18:19:06 2019 +0900 CAMEL-13886: camel-servlet + camel-http4 with null body causes "Stream closed" IOException Normally servlet request can be read only once, but when Exchange#getOut() is invoked HttpMessage may be copied for the out message with the original request that has been already read. This fix protects it from being read again. --- .../java/org/apache/camel/http/common/HttpMessage.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java index a799a08..6a0ea0c 100644 --- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java +++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java @@ -33,11 +33,13 @@ public class HttpMessage extends DefaultMessage { private final HttpServletRequest request; private final HttpServletResponse response; private final HttpCommonEndpoint endpoint; + private boolean requestRead; public HttpMessage(Exchange exchange, HttpCommonEndpoint endpoint, HttpServletRequest request, HttpServletResponse response) { setExchange(exchange); setCamelContext(exchange.getContext()); this.endpoint = endpoint; + this.requestRead = false; this.request = request; this.response = response; @@ -56,12 +58,14 @@ public class HttpMessage extends DefaultMessage { endpoint.getHttpBinding().readRequest(request, this); } - private HttpMessage(HttpServletRequest request, HttpServletResponse response, Exchange exchange, HttpCommonEndpoint endpoint) { + private HttpMessage(HttpServletRequest request, HttpServletResponse response, Exchange exchange, HttpCommonEndpoint endpoint, + boolean requestRead) { this.request = request; this.response = response; setExchange(getExchange()); this.endpoint = endpoint; setCamelContext(exchange.getContext()); + this.requestRead = requestRead; } public HttpServletRequest getRequest() { @@ -74,16 +78,23 @@ public class HttpMessage extends DefaultMessage { @Override protected Object createBody() { + // HTTP request may be read only once + if (requestRead) { + return null; + } + try { return endpoint.getHttpBinding().parseBody(this); } catch (IOException e) { throw new RuntimeCamelException(e); + } finally { + requestRead = true; } } @Override public HttpMessage newInstance() { - return new HttpMessage(request, response, getExchange(), endpoint); + return new HttpMessage(request, response, getExchange(), endpoint, requestRead); } @Override
