Repository: camel
Updated Branches:
  refs/heads/master 55cb57fba -> 65f9a3ab3


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/7790c6e0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7790c6e0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7790c6e0

Branch: refs/heads/master
Commit: 7790c6e0fe13af11593d7422bd88e59cb7a186f4
Parents: 55cb57f
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Jul 17 12:52:27 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Jul 17 12:52:27 2015 +0200

----------------------------------------------------------------------
 .../camel/component/http/DefaultHttpBinding.java    | 11 ++++++++++-
 .../apache/camel/component/http/HttpBinding.java    | 12 ++++++++++++
 .../apache/camel/component/http/HttpEndpoint.java   | 16 ++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7790c6e0/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
 
b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
index 3adcd02..ee5519f 100644
--- 
a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
+++ 
b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
@@ -60,6 +60,7 @@ public class DefaultHttpBinding implements HttpBinding {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(DefaultHttpBinding.class);
     private boolean useReaderForPayload;
+    private boolean eagerCheckContentAvailable;
     private boolean transferException;
     private HeaderFilterStrategy headerFilterStrategy = new 
HttpHeaderFilterStrategy();
 
@@ -450,7 +451,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
@@ -470,6 +471,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/7790c6e0/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 25d804d..5532ee7 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,6 +125,18 @@ 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.
+     */
+    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.
+     */
+    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/7790c6e0/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 bbaf54a..785e614 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
@@ -110,6 +110,10 @@ public class HttpEndpoint extends DefaultEndpoint 
implements HeaderFilterStrateg
     @UriParam(label = "producer",
             description = "If this option is true, The http producer won't 
read response body and cache the input stream")
     private boolean ignoreResponseBody;
+    @UriParam(label = "consumer",
+            description = "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.")
+    private boolean eagerCheckContentAvailable;
 
     public HttpEndpoint() {
     }
@@ -258,6 +262,7 @@ public class HttpEndpoint extends DefaultEndpoint 
implements HeaderFilterStrateg
             binding = new DefaultHttpBinding();
             binding.setHeaderFilterStrategy(getHeaderFilterStrategy());
             binding.setTransferException(isTransferException());
+            
binding.setEagerCheckContentAvailable(isEagerCheckContentAvailable());
         }
         return binding;
     }
@@ -491,4 +496,15 @@ 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.
+     * This can be used to turn off in case HTTP clients send streamed data 
and the available check must be delayed.
+     */
+    public void setEagerCheckContentAvailable(boolean 
eagerCheckContentAvailable) {
+        this.eagerCheckContentAvailable = eagerCheckContentAvailable;
+    }
 }

Reply via email to