You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/09/06 08:12:42 UTC

[camel] branch camel-2.22.x updated (b27897f -> 16dc6ac)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from b27897f  CAMEL-12779: camel-spring-redis - When stopping consumer it should stop the message listener
     new ee5f24f  CAMEL-12751 - Added Content-Length Test for incorrect length.
     new f3057d7  CAMEL-12751 - Default http4 producer to ignore content-length header.
     new d8d468f  CAMEL-12751 - Added documentation to ignoreContentLengthHeader parameter
     new 16dc6ac  CAMEL-12751 - Removed config. Instead ignoring content-length on streams

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/http4/HttpEntityConverter.java |  11 +-
 .../apache/camel/component/http4/HttpProducer.java |  11 +-
 ...est.java => HttpProducerContentLengthTest.java} | 247 +++++++++++----------
 3 files changed, 140 insertions(+), 129 deletions(-)
 copy components/camel-http4/src/test/java/org/apache/camel/component/http4/{HttpProducerContentTypeWithSemiColomnTest.java => HttpProducerContentLengthTest.java} (53%)


[camel] 01/04: CAMEL-12751 - Added Content-Length Test for incorrect length.

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ee5f24f194ddc1b4945bb5a8d00a92ea244c3545
Author: Bob Paulin <bo...@bobpaulin.com>
AuthorDate: Tue Aug 28 21:13:13 2018 -0500

    CAMEL-12751 - Added Content-Length Test for incorrect length.
---
 .../http4/HttpProducerContentLengthTest.java       | 101 +++++++++++++++++++++
 1 file changed, 101 insertions(+)

diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
new file mode 100644
index 0000000..462f62b
--- /dev/null
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.http4;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.converter.stream.ByteArrayInputStreamCache;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpRequestHandler;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HttpProducerContentLengthTest extends BaseHttpTest {
+    
+    private HttpServer localServer;
+    
+    private final String bodyContent = "{ \n \"content\"=\"This is content\" \n }";
+    
+    
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        localServer = ServerBootstrap.bootstrap().
+                setHttpProcessor(getBasicHttpProcessor()).
+                setConnectionReuseStrategy(getConnectionReuseStrategy()).
+                setResponseFactory(getHttpResponseFactory()).
+                setExpectationVerifier(getHttpExpectationVerifier()).
+                setSslContext(getSSLContext()).
+                registerHandler("/content", new HttpRequestHandler() {
+                    @Override
+                    public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
+                        Header contentLengthHeader = request.getFirstHeader(Exchange.CONTENT_LENGTH);
+                        String contentLength = contentLengthHeader != null ? contentLengthHeader.getValue() : "";
+                        
+                        //Should we expect the length in the case that we remove the header or should the header be empty?
+                        assertEquals(Integer.toString(bodyContent.length()), contentLength);
+                        response.setStatusCode(HttpStatus.SC_OK);
+                    }
+                }).create();
+        localServer.start();
+
+        super.setUp();
+    }
+
+    @After
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+    
+    @Test
+    public void testContentLengthIncorrect() throws Exception {
+        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(Exchange.CONTENT_LENGTH, "1000");
+                exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");
+                exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
+                exchange.getIn().setBody(new ByteArrayInputStreamCache(new ByteArrayInputStream(bodyContent.getBytes())));
+            }
+            
+        });
+
+        assertNotNull(out);
+        assertFalse("Should not fail", out.isFailed());
+        
+    }
+    
+    
+}
\ No newline at end of file


[camel] 03/04: CAMEL-12751 - Added documentation to ignoreContentLengthHeader parameter

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d8d468f69496134d770f1bb31df36107ae3444d7
Author: Bob Paulin <bo...@bobpaulin.com>
AuthorDate: Wed Aug 29 22:46:24 2018 -0500

    CAMEL-12751 - Added documentation to ignoreContentLengthHeader parameter
---
 .../main/java/org/apache/camel/component/http4/HttpEndpoint.java  | 8 ++++++++
 1 file changed, 8 insertions(+)

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 be54d54..9b7cf08 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
@@ -459,6 +459,14 @@ public class HttpEndpoint extends HttpCommonEndpoint {
     
     /**
      * Ignore Content-Length Header
+     * <p>
+     * Ignore the HTTP Content-Length Header when sending the 
+     * request to the HttpProducer.  Set this to false to explicitly 
+     * set Content-Length of a request body.
+     * </p>
+     * <p>
+     * Default: {@code true}
+     * </p>
      */
     public boolean isIgnoreContentLengthHeader() {
         return ignoreContentLengthHeader;


[camel] 04/04: CAMEL-12751 - Removed config. Instead ignoring content-length on streams

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 16dc6ac8a7bd102c70d57c1beb0f61cdafdaf85f
Author: Bob Paulin <bo...@bobpaulin.com>
AuthorDate: Wed Sep 5 20:56:15 2018 -0500

    CAMEL-12751 - Removed config. Instead ignoring content-length on streams
---
 .../src/main/java/org/apache/camel/Exchange.java    |  1 -
 .../apache/camel/component/http4/HttpEndpoint.java  | 21 ---------------------
 .../camel/component/http4/HttpEntityConverter.java  | 12 +-----------
 .../apache/camel/component/http4/HttpProducer.java  | 16 ++++------------
 .../http4/HttpProducerContentLengthTest.java        | 20 ++++++++++----------
 5 files changed, 15 insertions(+), 55 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java
index ded516f..6ca2ac6 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -160,7 +160,6 @@ public interface Exchange {
     String HTTP_SERVLET_REQUEST    = "CamelHttpServletRequest";
     String HTTP_SERVLET_RESPONSE   = "CamelHttpServletResponse";
 
-    String IGNORE_CONTENT_LENGTH_HEADER   = "CamelIgnoreContentLengthHeader";
     String INTERCEPTED_ENDPOINT = "CamelInterceptedEndpoint";
     String INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED = "CamelInterceptSendToEndpointWhenMatched";
     String INTERRUPTED = "CamelInterrupted";
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 9b7cf08..3c8f875 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
@@ -108,8 +108,6 @@ public class HttpEndpoint extends HttpCommonEndpoint {
     private int connectionsPerRoute;
     @UriParam(label = "security", description = "To use a custom X509HostnameVerifier such as DefaultHostnameVerifier or NoopHostnameVerifier")
     private HostnameVerifier x509HostnameVerifier;
-    @UriParam(label = "producer,proxy", description = "Ignore Content-Length Header")
-    private boolean ignoreContentLengthHeader = true;
 
     public HttpEndpoint() {
     }
@@ -456,24 +454,5 @@ public class HttpEndpoint extends HttpCommonEndpoint {
     public void setSocketTimeout(int socketTimeout) {
         this.socketTimeout = socketTimeout;
     }
-    
-    /**
-     * Ignore Content-Length Header
-     * <p>
-     * Ignore the HTTP Content-Length Header when sending the 
-     * request to the HttpProducer.  Set this to false to explicitly 
-     * set Content-Length of a request body.
-     * </p>
-     * <p>
-     * Default: {@code true}
-     * </p>
-     */
-    public boolean isIgnoreContentLengthHeader() {
-        return ignoreContentLengthHeader;
-    }
-    
-    public void setIgnoreContentLengthHeader(boolean ignoreContentLengthHeader) {
-        this.ignoreContentLengthHeader = ignoreContentLengthHeader;
-    }
 
 }
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 f827112..8236da8 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
@@ -22,10 +22,8 @@ import java.io.InputStream;
 
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.GZIPHelper;
-import org.apache.camel.util.ObjectHelper;
 import org.apache.http.HttpEntity;
 import org.apache.http.entity.AbstractHttpEntity;
 import org.apache.http.entity.ByteArrayEntity;
@@ -69,15 +67,7 @@ public final class HttpEntityConverter {
             entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream
                 ? stream.available() != 0 ? stream.available() : -1 : -1);
         } else {
-            Message inMessage = exchange.getIn();
-            String length = inMessage.getHeader(Exchange.CONTENT_LENGTH, String.class);
-            
-            if (exchange.getProperty(Exchange.IGNORE_CONTENT_LENGTH_HEADER, Boolean.FALSE, Boolean.class) || 
-                    ObjectHelper.isEmpty(length)) {
-                entity = new InputStreamEntity(in, -1);
-            } else {
-                entity = new InputStreamEntity(in, Long.parseLong(length));
-            }
+            entity = new InputStreamEntity(in, -1);
         }
         if (exchange != null) {
             String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index 6654a26..fa314ab 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -111,10 +111,7 @@ public class HttpProducer extends DefaultProducer {
                 skipRequestHeaders = URISupport.parseQuery(queryString, false, true);
             }
         }
-        
-        if(getEndpoint().isIgnoreContentLengthHeader()) {
-            exchange.setProperty(Exchange.IGNORE_CONTENT_LENGTH_HEADER, Boolean.TRUE);
-        }
+
         HttpRequestBase httpRequest = createMethod(exchange);
         Message in = exchange.getIn();
         String httpProtocolVersion = in.getHeader(Exchange.HTTP_PROTOCOL_VERSION, String.class);
@@ -562,14 +559,9 @@ public class HttpProducer extends DefaultProducer {
                     if (answer == null) {
                         // force the body as an input stream since this is the fallback
                         InputStream is = in.getMandatoryBody(InputStream.class);
-                        String length = in.getHeader(Exchange.CONTENT_LENGTH, String.class);
-                        InputStreamEntity entity = null;
-                        if (exchange.getProperty(Exchange.IGNORE_CONTENT_LENGTH_HEADER, Boolean.FALSE, Boolean.class) ||
-                                ObjectHelper.isEmpty(length)) {
-                            entity = new InputStreamEntity(is, -1);
-                        } else {
-                            entity = new InputStreamEntity(is, Long.parseLong(length));
-                        }
+                        
+                        InputStreamEntity entity = new InputStreamEntity(is, -1);
+                        
                         if (contentType != null) {
                             entity.setContentType(contentType.toString());
                         }
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
index fc28b86..ef71aa4 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
@@ -52,7 +52,7 @@ public class HttpProducerContentLengthTest extends BaseHttpTest {
                 setResponseFactory(getHttpResponseFactory()).
                 setExpectationVerifier(getHttpExpectationVerifier()).
                 setSslContext(getSSLContext()).
-                registerHandler("/content-ignore", new HttpRequestHandler() {
+                registerHandler("/content-streamed", new HttpRequestHandler() {
                     @Override
                     public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
                         Header contentLengthHeader = request.getFirstHeader(Exchange.CONTENT_LENGTH);
@@ -65,7 +65,7 @@ public class HttpProducerContentLengthTest extends BaseHttpTest {
                         assertEquals("chunked", transferEncoding);
                         response.setStatusCode(HttpStatus.SC_OK);
                     }
-                }).registerHandler("/content-no-ignore", new HttpRequestHandler() {
+                }).registerHandler("/content-not-streamed", new HttpRequestHandler() {
                     @Override
                     public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
                         Header contentLengthHeader = request.getFirstHeader(Exchange.CONTENT_LENGTH);
@@ -73,8 +73,8 @@ public class HttpProducerContentLengthTest extends BaseHttpTest {
                         Header transferEncodingHeader = request.getFirstHeader(Exchange.TRANSFER_ENCODING);
                         String transferEncoding = transferEncodingHeader != null ? transferEncodingHeader.getValue() : "";
                         
-                        //Content-Length was overridden to 10
-                        assertEquals("10", contentLength);
+                        //Content-Length should match byte array
+                        assertEquals("35", contentLength);
                         assertEquals("", transferEncoding);
                         response.setStatusCode(HttpStatus.SC_OK);
                     }
@@ -97,8 +97,8 @@ public class HttpProducerContentLengthTest extends BaseHttpTest {
     }
     
     @Test
-    public void testContentLengthIgnore() throws Exception {
-        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content-ignore?bridgeEndpoint=true", new Processor() {
+    public void testContentLengthStream() throws Exception {
+        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content-streamed?bridgeEndpoint=true", new Processor() {
 
             @Override
             public void process(Exchange exchange) throws Exception {
@@ -115,14 +115,14 @@ public class HttpProducerContentLengthTest extends BaseHttpTest {
     }
     
     @Test
-    public void testContentLengthNoIgnore() throws Exception {
-        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content-no-ignore?bridgeEndpoint=true&ignoreContentLengthHeader=false", new Processor() {
+    public void testContentLengthNotStreamed() throws Exception {
+        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content-not-streamed?bridgeEndpoint=true", new Processor() {
 
             @Override
             public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(Exchange.CONTENT_LENGTH, "10");
+                exchange.getIn().setHeader(Exchange.CONTENT_LENGTH, "1000");
                 exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");
-                exchange.getIn().setBody(new ByteArrayInputStreamCache(new ByteArrayInputStream(bodyContent.getBytes())));
+                exchange.getIn().setBody(bodyContent.getBytes());
             }
             
         });


[camel] 02/04: CAMEL-12751 - Default http4 producer to ignore content-length header.

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f3057d75b7548e09eb62892b503c4abc8544b1b7
Author: Bob Paulin <bo...@bobpaulin.com>
AuthorDate: Wed Aug 29 22:24:43 2018 -0500

    CAMEL-12751 - Default http4 producer to ignore content-length header.
---
 .../src/main/java/org/apache/camel/Exchange.java   |  1 +
 .../apache/camel/component/http4/HttpEndpoint.java | 13 ++++++
 .../camel/component/http4/HttpEntityConverter.java |  3 +-
 .../apache/camel/component/http4/HttpProducer.java |  7 +++-
 .../http4/HttpProducerContentLengthTest.java       | 49 ++++++++++++++++++----
 5 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java
index 6ca2ac6..ded516f 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -160,6 +160,7 @@ public interface Exchange {
     String HTTP_SERVLET_REQUEST    = "CamelHttpServletRequest";
     String HTTP_SERVLET_RESPONSE   = "CamelHttpServletResponse";
 
+    String IGNORE_CONTENT_LENGTH_HEADER   = "CamelIgnoreContentLengthHeader";
     String INTERCEPTED_ENDPOINT = "CamelInterceptedEndpoint";
     String INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED = "CamelInterceptSendToEndpointWhenMatched";
     String INTERRUPTED = "CamelInterrupted";
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 3c8f875..be54d54 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
@@ -108,6 +108,8 @@ public class HttpEndpoint extends HttpCommonEndpoint {
     private int connectionsPerRoute;
     @UriParam(label = "security", description = "To use a custom X509HostnameVerifier such as DefaultHostnameVerifier or NoopHostnameVerifier")
     private HostnameVerifier x509HostnameVerifier;
+    @UriParam(label = "producer,proxy", description = "Ignore Content-Length Header")
+    private boolean ignoreContentLengthHeader = true;
 
     public HttpEndpoint() {
     }
@@ -454,5 +456,16 @@ public class HttpEndpoint extends HttpCommonEndpoint {
     public void setSocketTimeout(int socketTimeout) {
         this.socketTimeout = socketTimeout;
     }
+    
+    /**
+     * Ignore Content-Length Header
+     */
+    public boolean isIgnoreContentLengthHeader() {
+        return ignoreContentLengthHeader;
+    }
+    
+    public void setIgnoreContentLengthHeader(boolean ignoreContentLengthHeader) {
+        this.ignoreContentLengthHeader = ignoreContentLengthHeader;
+    }
 
 }
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 bcbe502..f827112 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
@@ -72,7 +72,8 @@ public final class HttpEntityConverter {
             Message inMessage = exchange.getIn();
             String length = inMessage.getHeader(Exchange.CONTENT_LENGTH, String.class);
             
-            if (ObjectHelper.isEmpty(length)) {
+            if (exchange.getProperty(Exchange.IGNORE_CONTENT_LENGTH_HEADER, Boolean.FALSE, Boolean.class) || 
+                    ObjectHelper.isEmpty(length)) {
                 entity = new InputStreamEntity(in, -1);
             } else {
                 entity = new InputStreamEntity(in, Long.parseLong(length));
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index 36f49ff..6654a26 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -111,6 +111,10 @@ public class HttpProducer extends DefaultProducer {
                 skipRequestHeaders = URISupport.parseQuery(queryString, false, true);
             }
         }
+        
+        if(getEndpoint().isIgnoreContentLengthHeader()) {
+            exchange.setProperty(Exchange.IGNORE_CONTENT_LENGTH_HEADER, Boolean.TRUE);
+        }
         HttpRequestBase httpRequest = createMethod(exchange);
         Message in = exchange.getIn();
         String httpProtocolVersion = in.getHeader(Exchange.HTTP_PROTOCOL_VERSION, String.class);
@@ -560,7 +564,8 @@ public class HttpProducer extends DefaultProducer {
                         InputStream is = in.getMandatoryBody(InputStream.class);
                         String length = in.getHeader(Exchange.CONTENT_LENGTH, String.class);
                         InputStreamEntity entity = null;
-                        if (ObjectHelper.isEmpty(length)) {
+                        if (exchange.getProperty(Exchange.IGNORE_CONTENT_LENGTH_HEADER, Boolean.FALSE, Boolean.class) ||
+                                ObjectHelper.isEmpty(length)) {
                             entity = new InputStreamEntity(is, -1);
                         } else {
                             entity = new InputStreamEntity(is, Long.parseLong(length));
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
index 462f62b..fc28b86 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentLengthTest.java
@@ -52,17 +52,35 @@ public class HttpProducerContentLengthTest extends BaseHttpTest {
                 setResponseFactory(getHttpResponseFactory()).
                 setExpectationVerifier(getHttpExpectationVerifier()).
                 setSslContext(getSSLContext()).
-                registerHandler("/content", new HttpRequestHandler() {
+                registerHandler("/content-ignore", new HttpRequestHandler() {
                     @Override
                     public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
                         Header contentLengthHeader = request.getFirstHeader(Exchange.CONTENT_LENGTH);
                         String contentLength = contentLengthHeader != null ? contentLengthHeader.getValue() : "";
+                        Header transferEncodingHeader = request.getFirstHeader(Exchange.TRANSFER_ENCODING);
+                        String transferEncoding = transferEncodingHeader != null ? transferEncodingHeader.getValue() : "";
                         
-                        //Should we expect the length in the case that we remove the header or should the header be empty?
-                        assertEquals(Integer.toString(bodyContent.length()), contentLength);
+                        //Request Body Chunked if no Content-Length set.
+                        assertEquals("", contentLength);
+                        assertEquals("chunked", transferEncoding);
                         response.setStatusCode(HttpStatus.SC_OK);
                     }
-                }).create();
+                }).registerHandler("/content-no-ignore", new HttpRequestHandler() {
+                    @Override
+                    public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
+                        Header contentLengthHeader = request.getFirstHeader(Exchange.CONTENT_LENGTH);
+                        String contentLength = contentLengthHeader != null ? contentLengthHeader.getValue() : "";
+                        Header transferEncodingHeader = request.getFirstHeader(Exchange.TRANSFER_ENCODING);
+                        String transferEncoding = transferEncodingHeader != null ? transferEncodingHeader.getValue() : "";
+                        
+                        //Content-Length was overridden to 10
+                        assertEquals("10", contentLength);
+                        assertEquals("", transferEncoding);
+                        response.setStatusCode(HttpStatus.SC_OK);
+                    }
+                })
+                .create();
+            
         localServer.start();
 
         super.setUp();
@@ -79,14 +97,31 @@ public class HttpProducerContentLengthTest extends BaseHttpTest {
     }
     
     @Test
-    public void testContentLengthIncorrect() throws Exception {
-        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content", new Processor() {
+    public void testContentLengthIgnore() throws Exception {
+        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content-ignore?bridgeEndpoint=true", new Processor() {
 
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(Exchange.CONTENT_LENGTH, "1000");
                 exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");
-                exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
+                exchange.getIn().setBody(new ByteArrayInputStreamCache(new ByteArrayInputStream(bodyContent.getBytes())));
+            }
+            
+        });
+
+        assertNotNull(out);
+        assertFalse("Should not fail", out.isFailed());
+        
+    }
+    
+    @Test
+    public void testContentLengthNoIgnore() throws Exception {
+        Exchange out = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/content-no-ignore?bridgeEndpoint=true&ignoreContentLengthHeader=false", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(Exchange.CONTENT_LENGTH, "10");
+                exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");
                 exchange.getIn().setBody(new ByteArrayInputStreamCache(new ByteArrayInputStream(bodyContent.getBytes())));
             }