Updated Branches:
  refs/heads/camel-2.11.x 01fa3b52f -> 5438802c8

CAMEL-6402: HTTP4 - Set the content length for requests, if known
Thanks to Chris Geer for the patch


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5438802c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5438802c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5438802c

Branch: refs/heads/camel-2.11.x
Commit: 5438802c8b13a1d53f9339540b664130be57cce5
Parents: 01fa3b5
Author: cmueller <[email protected]>
Authored: Mon May 27 23:10:38 2013 +0200
Committer: cmueller <[email protected]>
Committed: Mon May 27 23:14:40 2013 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/util/GZIPHelper.java     |    4 +---
 .../camel/component/http4/HttpEntityConverter.java |   10 +++++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5438802c/camel-core/src/main/java/org/apache/camel/util/GZIPHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/GZIPHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/GZIPHelper.java
index d615260..c016d9a 100644
--- a/camel-core/src/main/java/org/apache/camel/util/GZIPHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/GZIPHelper.java
@@ -42,9 +42,8 @@ public final class GZIPHelper {
             return in;
         }
     }
-    
-    public static InputStream compressGzip(String contentEncoding, InputStream 
in) throws IOException {
 
+    public static InputStream compressGzip(String contentEncoding, InputStream 
in) throws IOException {
         if (isGzip(contentEncoding)) {
             ByteArrayOutputStream os = new ByteArrayOutputStream();
             GZIPOutputStream gzip = new GZIPOutputStream(os);
@@ -59,7 +58,6 @@ public final class GZIPHelper {
         } else {
             return in;
         }
-
     }
 
     public static InputStream compressGzip(String contentEncoding, byte[] 
data) throws IOException {

http://git-wip-us.apache.org/repos/asf/camel/blob/5438802c/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
 
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
index 5991e65..e88ceb5 100644
--- 
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
+++ 
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
@@ -61,7 +61,9 @@ public final class HttpEntityConverter {
         InputStreamEntity entity;
         if (!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, 
Boolean.class)) {
             String contentEncoding = 
exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
-            entity = new 
InputStreamEntity(GZIPHelper.compressGzip(contentEncoding, in), -1);        
+            InputStream stream = GZIPHelper.compressGzip(contentEncoding, in);
+            entity = new InputStreamEntity(stream, stream instanceof 
ByteArrayInputStream
+                ? stream.available() != 0 ? stream.available() : -1 : -1);
         } else {
             entity = new InputStreamEntity(in, -1);
         }
@@ -78,9 +80,11 @@ public final class HttpEntityConverter {
         InputStreamEntity entity;
         if (exchange != null && 
!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, 
Boolean.class)) {
             String contentEncoding = 
exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
-            entity = new 
InputStreamEntity(GZIPHelper.compressGzip(contentEncoding, data), -1);
+            InputStream stream = GZIPHelper.compressGzip(contentEncoding, 
data);
+            entity = new InputStreamEntity(stream, stream instanceof 
ByteArrayInputStream
+                ? stream.available() != 0 ? stream.available() : -1 : -1);
         } else {
-            entity = new InputStreamEntity(new ByteArrayInputStream(data), -1);
+            entity = new InputStreamEntity(new ByteArrayInputStream(data), 
data.length);
         }
         if (exchange != null) {
             String contentEncoding = 
exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);

Reply via email to