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:07:37 UTC

[2/3] 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/6ee8743f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6ee8743f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6ee8743f

Branch: refs/heads/master
Commit: 6ee8743fae9fe4cd64e37b2511872045fa1f74c1
Parents: 660ebaa
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:05:31 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/6ee8743f/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 97c81c0..3adcd02 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
@@ -458,7 +458,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/6ee8743f/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 edee4b4..e5bbf45 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
@@ -160,14 +160,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.
      *
@@ -176,7 +176,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;
         }
@@ -196,6 +196,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.
      *