camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 04/04: CAMEL-12751 - Removed config. Instead ignoring content-length on streams
Date Thu, 06 Sep 2018 08:12:46 GMT
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 <bob@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());
             }
             
         });


Mime
View raw message