You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/03/22 13:21:28 UTC

svn commit: r926047 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ components/camel-http/src/main/java/org/apache/camel/component/http/ components/camel-jetty/src/test/java/org/apache/camel/component/jetty/

Author: davsclaus
Date: Mon Mar 22 12:21:28 2010
New Revision: 926047

URL: http://svn.apache.org/viewvc?rev=926047&view=rev
Log:
CAMEL-2566: Applied patch with thanks to Freeman.

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=926047&r1=926046&r2=926047&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Mon Mar 22 12:21:28 2010
@@ -32,12 +32,10 @@ import org.apache.camel.spi.UnitOfWork;
 public interface Exchange {
 
     String ACCEPT_CONTENT_TYPE = "CamelAcceptContentType";
-
     @Deprecated
     String AGGREGATED_INDEX = "CamelAggregatedIndex";
     String AGGREGATED_SIZE  = "CamelAggregatedSize";
     String AGGREGATED_COMPLETED_BY = "CamelAggregatedCompletedBy";
-
     String ASYNC_WAIT = "CamelAsyncWait";
 
     String BATCH_INDEX    = "CamelBatchIndex";
@@ -82,6 +80,8 @@ public interface Exchange {
     String HTTP_URI                = "CamelHttpUri";
     String HTTP_URL                = "CamelHttpUrl";
     String HTTP_CHUNKED            = "CamelHttpChunked";
+    String HTTP_SERVLET_REQUEST = "CamelHttpServletRequest";
+    String HTTP_SERVLET_RESPONSE = "CamelHttpServletResponse";
 
     String INTERCEPTED_ENDPOINT = "CamelInterceptedEndpoint";
     String TO_ENDPOINT          = "CamelToEndpoint";
@@ -102,25 +102,21 @@ public interface Exchange {
     String ROLLBACK_ONLY      = "CamelRollbackOnly";
     String ROLLBACK_ONLY_LAST = "CamelRollbackOnlyLast";
 
+    String SOAP_ACTION = "CamelSoapAction";
     String SPLIT_INDEX = "CamelSplitIndex";
     String SPLIT_SIZE  = "CamelSplitSize";
 
-    String TIMER_FIRED_TIME = "CamelTimerFiredTime";
-    String TIMER_NAME       = "CamelTimerName";
-    String TIMER_PERIOD     = "CamelTimerPeriod";
-    String TIMER_TIME       = "CamelTimerTime";
-
-    String TRANSACTED = "CamelTransacted";
-
+    String TRANSACTED        = "CamelTransacted";
+    String TRANSFER_ENCODING = "Transfer-Encoding";
     String TRACE_EVENT           = "CamelTraceEvent";
     String TRACE_EVENT_NODE_ID   = "CamelTraceEventNodeId";
     String TRACE_EVENT_TIMESTAMP = "CamelTraceEventTimestamp";
     String TRACE_EVENT_EXCHANGE  = "CamelTraceEventExchange";
-    
-    String SOAP_ACTION = "CamelSoapAction";
-    
-    String HTTP_SERVLET_REQUEST = "CamelHttpServletRequest";
-    String HTTP_SERVLET_RESPONSE = "CamelHttpServletResponse";
+
+    String TIMER_FIRED_TIME = "CamelTimerFiredTime";
+    String TIMER_NAME       = "CamelTimerName";
+    String TIMER_PERIOD     = "CamelTimerPeriod";
+    String TIMER_TIME       = "CamelTimerTime";
 
     /**
      * Returns the {@link ExchangePattern} (MEP) of this exchange.

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=926047&r1=926046&r2=926047&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Mon Mar 22 12:21:28 2010
@@ -138,6 +138,9 @@ public class DefaultHttpBinding implemen
             String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING, String.class);
             response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding);
         }
+        if (checkChunked(response, response.getExchange())) {
+            response.setHeader(Exchange.TRANSFER_ENCODING, "chunked");
+        }
     }
 
     public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
@@ -188,7 +191,7 @@ public class DefaultHttpBinding implemen
 
     protected void doWriteDirectResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
         InputStream is = null;
-        if (checkChucked(message, exchange)) {
+        if (checkChunked(message, exchange)) {
             is = message.getBody(InputStream.class);
         }
         if (is != null) {
@@ -220,7 +223,7 @@ public class DefaultHttpBinding implemen
         }
     }
 
-    protected boolean checkChucked(Message message, Exchange exchange) {
+    protected boolean checkChunked(Message message, Exchange exchange) {
         boolean answer = true;
         if (message.getHeader(Exchange.HTTP_CHUNKED) == null) {
             // check the endpoint option

Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java?rev=926047&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java Mon Mar 22 12:21:28 2010
@@ -0,0 +1,92 @@
+/**
+ * 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.jetty;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HttpClientRouteEnableChunkedTest extends CamelTestSupport {
+
+    @Test
+    public void testHttpRouteWithOption() throws Exception {
+        testHttpClient("direct:start2");
+    }
+    
+    private void testHttpClient(String uri) throws Exception {
+        System.getProperties().put("HTTPClient.dontChunkRequests", "yes");
+
+        MockEndpoint mockEndpoint = getMockEndpoint("mock:a");
+        mockEndpoint.expectedBodiesReceived("<b>Hello World</b>");
+
+        template.requestBodyAndHeader(uri, new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml");
+        
+        mockEndpoint.assertIsSatisfied();
+        List<Exchange> list = mockEndpoint.getReceivedExchanges();
+        Exchange exchange = list.get(0);
+        assertNotNull("exchange", exchange);
+
+        Message in = exchange.getIn();
+        assertNotNull("in", in);
+
+        Map<String, Object> headers = in.getHeaders();
+        
+        log.info("Headers: " + headers);
+        
+        assertTrue("Should be more than one header but was: " + headers, headers.size() > 0);
+        
+        // should get the Content-Length
+        assertEquals("Should get the transfer-encoding as chunked", "chunked", headers.get("Transfer-Encoding"));
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                errorHandler(noErrorHandler());
+
+                Processor clientProc = new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        assertIsInstanceOf(InputStream.class, exchange.getIn().getBody());
+                    }
+                };
+                
+                from("direct:start2").to("http://localhost:9081/hello").to("mock:a");
+                
+                Processor proc = new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        ByteArrayInputStream bis = new ByteArrayInputStream("<b>Hello World</b>".getBytes());                        
+                        exchange.getOut().setBody(bis);
+                    }
+                };
+                
+                from("jetty:http://localhost:9081/hello").process(proc);
+            }
+        };
+    }    
+  
+
+}

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date