CAMEL-8821 Fixed the test errors in camel-http4
Conflicts:
components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7a5d8b98
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7a5d8b98
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7a5d8b98
Branch: refs/heads/camel-2.15.x
Commit: 7a5d8b986d9a3e9d5b15340dfa9bdb8bccac6b7f
Parents: 9ad9e4e
Author: Willem Jiang <[email protected]>
Authored: Sun May 31 17:05:53 2015 +0800
Committer: Willem Jiang <[email protected]>
Committed: Sun May 31 17:17:45 2015 +0800
----------------------------------------------------------------------
.../component/http4/DefaultHttpBinding.java | 2 +-
.../component/http4/helper/HttpHelper.java | 41 +++++++++++++++-----
2 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7a5d8b98/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 26c846b..ed03770 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
@@ -419,7 +419,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/7a5d8b98/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 951dd0e..81b7161 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
@@ -121,27 +121,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;
}
@@ -153,8 +153,29 @@ public final class HttpHelper {
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);