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 2015/05/31 11:30:35 UTC

[04/10] camel git commit: CAMEL-8821 Fixed the test errors in camel-http

CAMEL-8821 Fixed the test errors in camel-http


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

Branch: refs/heads/camel-2.15.x
Commit: 9ad9e4e5915c704512449f48cd3f47528f4fc3e3
Parents: f725a8b
Author: Willem Jiang <wi...@gmail.com>
Authored: Sun May 31 17:05:31 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Sun May 31 17:14:39 2015 +0800

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


http://git-wip-us.apache.org/repos/asf/camel/blob/9ad9e4e5/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 89a34c8..7a0beb7 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
@@ -456,7 +456,7 @@ public class DefaultHttpBinding implements HttpBinding {
                 }
             }
             // read the response body from servlet request
-            return HttpHelper.readResponseBodyFromServletRequest(request, httpMessage.getExchange());
+            return HttpHelper.readRequestBodyFromServletRequest(request, httpMessage.getExchange());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/9ad9e4e5/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.
      *