You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/03/12 05:11:42 UTC

svn commit: r752767 - in /camel/branches/camel-1.x: ./ components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java

Author: ningjiang
Date: Thu Mar 12 04:11:41 2009
New Revision: 752767

URL: http://svn.apache.org/viewvc?rev=752767&view=rev
Log:
Merged revisions 752418 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r752418 | ningjiang | 2009-03-11 18:29:36 +0800 (Wed, 11 Mar 2009) | 1 line
  
  CAMEL-1445 http producer will return a cached stream
........

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 12 04:11:41 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752751-752755
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=752767&r1=752766&r2=752767&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Thu Mar 12 04:11:41 2009
@@ -30,6 +30,7 @@
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.http.helper.GZIPHelper;
 import org.apache.camel.component.http.helper.LoadingByteArrayOutputStream;
+import org.apache.camel.converter.stream.CachedOutputStream;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.ObjectHelper;
@@ -92,7 +93,7 @@
 
                 answer.setHeaders(in.getHeaders());
                 answer.setHeader(HTTP_RESPONSE_CODE, responseCode);
-                answer.setBody(extractResponseBody(method));
+                answer.setBody(extractResponseBody(method, exchange));
 
                 // propagate HTTP response headers
                 Header[] headers = method.getResponseHeaders();
@@ -106,7 +107,7 @@
             } else {
                 HttpOperationFailedException exception = null;
                 Header[] headers = method.getResponseHeaders();
-                InputStream is =  extractResponseBody(method);
+                InputStream is = extractResponseBody(method, exchange);
                 if (responseCode >= 300 && responseCode < 400) {
                     String redirectLocation;
                     Header locationHeader = method.getResponseHeader("location");
@@ -150,22 +151,21 @@
      * @return  the response as a stream
      * @throws IOException can be thrown
      */
-    protected static InputStream extractResponseBody(HttpMethod method) throws IOException {
-        LoadingByteArrayOutputStream bos = null;
+    protected static InputStream extractResponseBody(HttpMethod method, Exchange exchange) throws IOException {
+        CachedOutputStream cos = null;
         InputStream is = null;
         try {
-            bos = new LoadingByteArrayOutputStream();
+            cos = new CachedOutputStream(exchange.getContext().getProperties());
             is = GZIPHelper.getInputStream(method);            
             // in case of no response stream
             if (is == null) {
                 return null;
             }
-            IOUtils.copy(is, bos);
-            bos.flush();
-            return bos.createInputStream();
+            IOUtils.copy(is, cos);
+            cos.flush();
+            return cos.getInputStream();
         } finally {
-            ObjectHelper.close(is, "Extracting response body", LOG);
-            ObjectHelper.close(bos, "Extracting response body", LOG);
+            ObjectHelper.close(is, "Extracting response body", LOG);            
         }
     }