This is an automated email from the ASF dual-hosted git repository. tsato 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 1db32cb CAMEL-13886: camel-servlet + camel-http4 with null body causes "Stream closed" IOException 1db32cb is described below commit 1db32cb51c0a4f28d603003f9a4aeec5dc5a30cf Author: Tadayoshi Sato <sato.tadayo...@gmail.com> 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 213566c..de79734 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 @@ -30,9 +30,11 @@ 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) { super(exchange); + this.requestRead = false; this.endpoint = endpoint; this.request = request; @@ -52,11 +54,13 @@ 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) { super(exchange); this.request = request; this.response = response; this.endpoint = endpoint; + this.requestRead = requestRead; } public HttpServletRequest getRequest() { @@ -69,16 +73,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