CAMEL-8821 Fixed the test errors in camel-http

Conflicts:
        
components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/209bac54
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/209bac54
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/209bac54

Branch: refs/heads/camel-2.14.x
Commit: 209bac5445c572b3f4dbdd75d913095ae87a7831
Parents: bad5acf
Author: Willem Jiang <[email protected]>
Authored: Sun May 31 17:05:31 2015 +0800
Committer: Willem Jiang <[email protected]>
Committed: Sun May 31 17:27:29 2015 +0800

----------------------------------------------------------------------
 .../component/http/DefaultHttpBinding.java      |  4 +--
 .../camel/component/http/helper/HttpHelper.java | 31 +++++++++++++++++---
 2 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/209bac54/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
 
b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
index ba154dd..2505f60 100644
--- 
a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
+++ 
b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
@@ -445,8 +445,8 @@ public class DefaultHttpBinding implements HttpBinding {
             // use reader to read the response body
             return request.getReader();
         } else {
-            // reade the response body from servlet request
-            return HttpHelper.readResponseBodyFromServletRequest(request, 
httpMessage.getExchange());
+            // read the response body from servlet request
+            return HttpHelper.readRequestBodyFromServletRequest(request, 
httpMessage.getExchange());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/209bac54/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
 
b/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
index ecd66c7..795da5d 100644
--- 
a/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
+++ 
b/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java
@@ -141,14 +141,14 @@ public final class HttpHelper {
      *
      * @param request  http servlet request
      * @param exchange the exchange
-     * @return the response body, can be <tt>null</tt> if no body
+     * @return the request body, can be <tt>null</tt> if no body
      * @throws IOException is thrown if error reading response body
      */
-    public static Object readResponseBodyFromServletRequest(HttpServletRequest 
request, Exchange exchange) throws IOException {
+    public static Object readRequestBodyFromServletRequest(HttpServletRequest 
request, Exchange exchange) throws IOException {
         InputStream is = HttpConverter.toInputStream(request, exchange);
         return readResponseBodyFromInputStream(is, exchange);
     }
-
+    
     /**
      * Reads the response body from the given input stream.
      *
@@ -157,7 +157,7 @@ public final class HttpHelper {
      * @return the response body, can be <tt>null</tt> if no body
      * @throws IOException is thrown if error reading response body
      */
-    public static Object readResponseBodyFromInputStream(InputStream is, 
Exchange exchange) throws IOException {
+    public static Object readRequestBodyFromInputStream(InputStream is, 
Exchange exchange) throws IOException {
         if (is == null) {
             return null;
         }
@@ -177,6 +177,29 @@ public final class HttpHelper {
         }
     }
 
+
+    /**
+     * Reads the response body from the given input stream.
+     *
+     * @param is       the input stream
+     * @param exchange the exchange
+     * @return the response body, can be <tt>null</tt> if no body
+     * @throws IOException is thrown if error reading response body
+     */
+    public static Object readResponseBodyFromInputStream(InputStream is, 
Exchange exchange) throws IOException {
+        if (is == null) {
+            return null;
+        }
+        // convert the input stream to StreamCache if the stream cache is not 
disabled
+        if (exchange.getProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, 
Boolean.FALSE, Boolean.class)) {
+            return is;
+        } else {
+            CachedOutputStream cos = new CachedOutputStream(exchange);
+            IOHelper.copyAndCloseInput(is, cos);
+            return cos.newStreamCache();
+        }
+    }
+
     /**
      * Creates the URL to invoke.
      *

Reply via email to