CAMEL-8643: Do not eager check for content available using the input stream available in case http client is in streaming mode and is slow at sending data.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/65f9a3ab Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/65f9a3ab Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/65f9a3ab Branch: refs/heads/master Commit: 65f9a3ab349c4b1b0545da33b3ccbee523f93880 Parents: 7790c6e Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Jul 17 12:57:55 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Jul 17 12:58:03 2015 +0200 ---------------------------------------------------------------------- .../org/apache/camel/component/http/HttpBinding.java | 8 ++++---- .../apache/camel/component/http/HttpEndpoint.java | 4 ++-- .../camel/component/http4/DefaultHttpBinding.java | 11 ++++++++++- .../apache/camel/component/http4/HttpBinding.java | 12 ++++++++++++ .../apache/camel/component/http4/HttpEndpoint.java | 15 +++++++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/65f9a3ab/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java index 5532ee7..10141ae 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpBinding.java @@ -125,14 +125,14 @@ public interface HttpBinding { boolean isTransferException(); /** - * Whether to eager check whether the HTTP requests has content. - * This can be used to turn off in case HTTP clients send streamed data and the available check must be delayed. + * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. + * This can be turned on in case HTTP clients do not send streamed data. */ boolean isEagerCheckContentAvailable(); /** - * Whether to eager check whether the HTTP requests has content. - * This can be used to turn off in case HTTP clients send streamed data and the available check must be delayed. + * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. + * This can be turned on in case HTTP clients do not send streamed data. */ void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable); http://git-wip-us.apache.org/repos/asf/camel/blob/65f9a3ab/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java index 785e614..fcdd6a4 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java @@ -501,8 +501,8 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg } /** - * Whether to eager check whether the HTTP requests has content. - * This can be used to turn off in case HTTP clients send streamed data and the available check must be delayed. + * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. + * This can be turned on in case HTTP clients do not send streamed data. */ public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) { this.eagerCheckContentAvailable = eagerCheckContentAvailable; http://git-wip-us.apache.org/repos/asf/camel/blob/65f9a3ab/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java index 233c09f..4420c69 100644 --- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java +++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java @@ -61,6 +61,7 @@ public class DefaultHttpBinding implements HttpBinding { private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpBinding.class); private boolean useReaderForPayload; private boolean transferException; + private boolean eagerCheckContentAvailable; private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy(); public DefaultHttpBinding() { @@ -413,7 +414,7 @@ public class DefaultHttpBinding implements HttpBinding { return request.getReader(); } else { // if we do not know if there is any data at all, then make sure to check the stream first - if (len < 0) { + if (len < 0 && isEagerCheckContentAvailable()) { InputStream is = request.getInputStream(); if (is.available() == 0) { // no data so return null @@ -433,6 +434,14 @@ public class DefaultHttpBinding implements HttpBinding { this.useReaderForPayload = useReaderForPayload; } + public boolean isEagerCheckContentAvailable() { + return eagerCheckContentAvailable; + } + + public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) { + this.eagerCheckContentAvailable = eagerCheckContentAvailable; + } + public boolean isTransferException() { return transferException; } http://git-wip-us.apache.org/repos/asf/camel/blob/65f9a3ab/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java index 6f667e8..3c8b87d 100644 --- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java +++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java @@ -116,6 +116,18 @@ public interface HttpBinding { void setUseReaderForPayload(boolean useReaderForPayload); /** + * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. + * This can be turned on in case HTTP clients do not send streamed data. + */ + boolean isEagerCheckContentAvailable(); + + /** + * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. + * This can be turned on in case HTTP clients do not send streamed data. + */ + void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable); + + /** * If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back * serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or * Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, http://git-wip-us.apache.org/repos/asf/camel/blob/65f9a3ab/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java index 6dfd1b7..a8e0132 100644 --- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java +++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java @@ -89,6 +89,8 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg private boolean clearExpiredCookies = true; @UriParam(label = "producer") private boolean ignoreResponseBody; + @UriParam(label = "consumer") + private boolean eagerCheckContentAvailable; public HttpEndpoint() { } @@ -259,6 +261,7 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg httpBinding = new DefaultHttpBinding(); httpBinding.setHeaderFilterStrategy(getHeaderFilterStrategy()); httpBinding.setTransferException(isTransferException()); + httpBinding.setEagerCheckContentAvailable(isEagerCheckContentAvailable()); } return httpBinding; } @@ -489,4 +492,16 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg this.ignoreResponseBody = ignoreResponseBody; } + public boolean isEagerCheckContentAvailable() { + return eagerCheckContentAvailable; + } + + /** + * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. + * This can be turned on in case HTTP clients do not send streamed data. + */ + public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) { + this.eagerCheckContentAvailable = eagerCheckContentAvailable; + } + }