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:38 UTC

[3/3] camel git commit: CAMEL-8821 Fixed the test errors in camel-http4

CAMEL-8821 Fixed the test errors in camel-http4


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

Branch: refs/heads/master
Commit: 0b4a1675dacd278f0ccd342f1dc4c696dd281c11
Parents: 6ee8743
Author: Willem Jiang <wi...@gmail.com>
Authored: Sun May 31 17:05:53 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Sun May 31 17:05:53 2015 +0800

----------------------------------------------------------------------
 .../component/http4/DefaultHttpBinding.java     |  2 +-
 .../component/http4/helper/HttpHelper.java      | 43 +++++++++++++++-----
 2 files changed, 33 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0b4a1675/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
index c7a9e2c..233c09f 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
@@ -421,7 +421,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/0b4a1675/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
index 4201ed9..d1996bc 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
@@ -140,27 +140,27 @@ public final class HttpHelper {
     }
 
     /**
-     * Reads the response body from the given http servlet request.
+     * Reads the request body from the given http servlet request.
      *
      * @param request  http servlet request
      * @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
+     * @return the request body, can be <tt>null</tt> if no body
+     * @throws IOException is thrown if error reading request 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);
+        return readRequestBodyFromInputStream(is, exchange);
     }
-
+    
     /**
-     * Reads the response body from the given input stream.
+     * Reads the request 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
+     * @return the request body, can be <tt>null</tt> if no body
+     * @throws IOException is thrown if error reading request 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;
         }
@@ -171,9 +171,30 @@ public final class HttpHelper {
             DefaultCamelContext context = (DefaultCamelContext) exchange.getContext();
             disableStreamCaching = !context.isStreamCaching();
         }
+        if (disableStreamCaching) {
+            return is;
+        } else {
+            CachedOutputStream cos = new CachedOutputStream(exchange);
+            IOHelper.copyAndCloseInput(is, cos);
+            return cos.newStreamCache();
+        }
+    }
+
+    /**
+     * 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, disableStreamCaching, Boolean.class)) {
+        if (exchange.getProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.FALSE, Boolean.class)) {
             return is;
         } else {
             CachedOutputStream cos = new CachedOutputStream(exchange);