camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Käufl <paul.kae...@tngtech.com>
Subject Stream closed exception when using camel as http proxy with tomcat servlet
Date Fri, 04 Aug 2017 16:31:27 GMT
Hello,

following the example provided in
http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html,
we are using a route definition as follows to proxy an http endpoint via
a servlet running in Tomcat 8.5.16:

from("servlet:///?matchOnUriPrefix=true")

.to("http4://localhost:8080/respondsWith304?bridgeEndpoint=true&throwExceptionOnFailure=false");

Whenever the http endpoint responds with a status code 304 or - more
specifically - with one of the status codes listed in
org.apache.http.protocol.HttpRequestExecutor#canResponseHaveBody,
a "java.io.IOException: Stream closed" is logged and the servlet replies
with HTTP Status 500 – Internal Server Error.

I've assembled a (rather) minimal working example to reproduce the
issue: https://github.com/kaeufl/camel-http-proxy-stream-closed-issue

We're experiencing the issue with both the latest camel release 2.19.2
as well as the current master branch.

We can workaround the issue by
 (a) either disabling stream caching for the servlet component
explicitly, by writing:
from("servlet:///?matchOnUriPrefix=true&disableStreamCache=true")
 (b) or by converting the request(!) body to String in the route:
from("servlet:///?matchOnUriPrefix=true").convertBodyTo(String.class)

As far as I understand (and my understanding of camel is still very
limited), there are two problems with this:

1) Shouldn't stream caching be disabled by default? At least that's what
I understood from http://camel.apache.org/stream-caching.html

The method
org.apache.camel.http.common.HttpHelper#readRequestBodyFromServletRequest
oddly calls the method readResponseBodyFromInputStream() which does NOT
seem to take the global stream caching setting into account...

2) The actual issue seems to be a null response body in the HttpMessage
contained in the exchange after
org.apache.camel.component.http4.HttpProducer#populateResponse.

Due to the response body being set to null, it is later tried to re-read
the request (!) body in
org.apache.camel.http.common.DefaultHttpBinding#doWriteResponse, line 391.

If someone can confirm that this is indeed a bug, I'd be happy to open
an issue. It is yet a little unclear to me, however, where the root of
the problem actually lies.

Also I couldn't figure out how to write a camel integration test that
makes use of the servlet component. I'd really appreciate if someone
could point me at an example.

Also note that we couldn't reproduce the behaviour with jetty as a
servlet container.

Kind regards and thanks for your help,
Paul

-- 
Paul Käufl * paul.kaeufl@tngtech.com * +49-1520-7182305
TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterföhring
Geschäftsführer: Henrik Klagges, Dr. Robert Dahlke, Gerhard Müller
Sitz: Unterföhring * Amtsgericht München * HRB 135082

Mime
View raw message