camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r895572 - in /camel/trunk/components: camel-http/src/main/java/org/apache/camel/component/http/ camel-jetty/src/test/java/org/apache/camel/component/jetty/
Date Mon, 04 Jan 2010 07:28:39 GMT
Author: ningjiang
Date: Mon Jan  4 07:28:28 2010
New Revision: 895572

URL: http://svn.apache.org/viewvc?rev=895572&view=rev
Log:
CAMEL-2329 added chunked option into camel-jetty endpoint

Modified:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java

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=895572&r1=895571&r2=895572&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 Jan  4 07:28:28 2010
@@ -25,6 +25,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
@@ -173,7 +174,10 @@
     }
 
     protected void doWriteDirectResponse(Message message, HttpServletResponse response, Exchange
exchange) throws IOException {
-        InputStream is = message.getBody(InputStream.class);
+        InputStream is = null;
+        if (checkChucked(message, exchange)) {
+            is = message.getBody(InputStream.class);
+        }
         if (is != null) {
             ServletOutputStream os = response.getOutputStream();
             try {
@@ -203,6 +207,20 @@
         }
     }
 
+    protected boolean checkChucked(Message message, Exchange exchange) {
+        boolean answer = true;
+        if (message.getHeader(Exchange.HTTP_CHUNKED) == null) {
+            // check the endpoint option
+            Endpoint endpoint = exchange.getFromEndpoint();
+            if (endpoint instanceof HttpEndpoint) {
+                answer = ((HttpEndpoint)endpoint).isChunked();
+            }
+        } else {
+            answer = message.getHeader(Exchange.HTTP_CHUNKED, boolean.class);
+        }
+        return answer;
+    }
+
     protected void doWriteGZIPResponse(Message message, HttpServletResponse response, Exchange
exchange) throws IOException {
         byte[] bytes;
         try {

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=895572&r1=895571&r2=895572&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
Mon Jan  4 07:28:28 2010
@@ -48,6 +48,7 @@
     private boolean throwExceptionOnFailure = true;
     private boolean bridgeEndpoint;
     private boolean matchOnUriPrefix;
+    private boolean chunked = true;
 
     public HttpEndpoint() {
     }
@@ -234,4 +235,12 @@
     public void setMatchOnUriPrefix(boolean match) {
         this.matchOnUriPrefix = match;
     }
+    
+    public boolean isChunked() {
+        return this.chunked;
+    }
+    
+    public void setChunked(boolean chunked) {
+        this.chunked = chunked;
+    }
 }

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java?rev=895572&r1=895571&r2=895572&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java
Mon Jan  4 07:28:28 2010
@@ -33,13 +33,22 @@
 public class HttpClientRouteTest extends CamelTestSupport {
 
     @Test
-    public void testHttpClient() throws Exception {
+    public void testHttpRouteWithMessageHeader() throws Exception {
+        testHttpClient("direct:start");
+    }
+    
+    @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("direct:start", new ByteArrayInputStream("This is a
test".getBytes()), "Content-Type", "application/xml");
+        template.requestBodyAndHeader(uri, new ByteArrayInputStream("This is a test".getBytes()),
"Content-Type", "application/xml");
         
         mockEndpoint.assertIsSatisfied();
         List<Exchange> list = mockEndpoint.getReceivedExchanges();
@@ -50,10 +59,13 @@
         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
+        assertNotNull("Should get the content-lenghth ", headers.get("Content-Length"));
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -68,14 +80,17 @@
                 };
                 
                 from("direct:start").to("http://localhost:9080/hello").process(clientProc).convertBodyTo(String.class).to("mock:a");
-               
+                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:9080/hello").process(proc);
+                from("jetty:http://localhost:9080/hello").process(proc).setHeader(Exchange.HTTP_CHUNKED).constant(false);
+                
+                from("jetty:http://localhost:9081/hello?chunked=false").process(proc);
             }
         };
     }    



Mime
View raw message