You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/09/24 20:26:00 UTC
[camel] branch main updated: CAMEL-14823: Fixed so camel-servlet
honours when stream caching is disabled.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 0b5b1f9 CAMEL-14823: Fixed so camel-servlet honours when stream caching is disabled.
0b5b1f9 is described below
commit 0b5b1f9058522746855b1c941634340812c6a41b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Sep 24 22:25:32 2021 +0200
CAMEL-14823: Fixed so camel-servlet honours when stream caching is disabled.
---
.../org/apache/camel/http/common/HttpHelper.java | 23 +++++++++-------------
.../camel/component/http/HttpPollingConsumer.java | 11 +++++------
.../ROOT/pages/camel-3x-upgrade-guide-3_12.adoc | 6 ++++++
3 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
index d158501..590dc6b 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
@@ -139,8 +139,7 @@ public final class HttpHelper {
*/
public static Object readRequestBodyFromServletRequest(HttpServletRequest request, Exchange exchange) throws IOException {
InputStream is = HttpConverter.toInputStream(request, exchange);
- // TODO should readRequestBodyFromInputStream() be invoked instead?
- return readResponseBodyFromInputStream(is, exchange);
+ return readRequestBodyFromInputStream(is, exchange);
}
/**
@@ -148,7 +147,7 @@ public final class HttpHelper {
*
* @param is the input stream
* @param exchange the exchange
- * @return the request body, can be <tt>null</tt> if no body
+ * @return the request body, can be <tt>null</tt> if there is no request body
* @throws IOException is thrown if error reading request body
*/
public static Object readRequestBodyFromInputStream(InputStream is, Exchange exchange) throws IOException {
@@ -167,25 +166,21 @@ public final class HttpHelper {
}
/**
- * Reads the response body from the given input stream.
+ * Caches the response body from the given input stream, which is needed by
+ * {@link org.apache.camel.PollingConsumer}.
*
* @param is the input stream
* @param exchange the exchange
- * @return the response body, can be <tt>null</tt> if no body
+ * @return the cached response body
* @throws IOException is thrown if error reading response body
*/
- public static Object readResponseBodyFromInputStream(InputStream is, Exchange exchange) throws IOException {
+ public static Object cacheResponseBodyFromInputStream(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();
- }
+ CachedOutputStream cos = new CachedOutputStream(exchange);
+ IOHelper.copyAndCloseInput(is, cos);
+ return cos.newStreamCache();
}
/**
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
index 437f701..4359d8d 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
@@ -49,7 +49,6 @@ public class HttpPollingConsumer extends PollingConsumerSupport {
this.endpoint = endpoint;
this.httpContext = endpoint.getHttpContext();
this.httpClient = endpoint.getHttpClient();
-
}
@Override
@@ -83,13 +82,13 @@ public class HttpPollingConsumer extends PollingConsumerSupport {
httpClientContext.setRequestConfig(requestConfig);
}
- HttpEntity responeEntity = null;
+ HttpEntity responseEntity = null;
try {
// execute request
HttpResponse response = executeMethod(method, httpClientContext);
int responseCode = response.getStatusLine().getStatusCode();
- responeEntity = response.getEntity();
- Object body = HttpHelper.readResponseBodyFromInputStream(responeEntity.getContent(), exchange);
+ responseEntity = response.getEntity();
+ Object body = HttpHelper.cacheResponseBodyFromInputStream(responseEntity.getContent(), exchange);
// lets store the result in the output message.
Message message = exchange.getOut();
@@ -118,9 +117,9 @@ public class HttpPollingConsumer extends PollingConsumerSupport {
} catch (IOException e) {
throw new RuntimeCamelException(e);
} finally {
- if (responeEntity != null) {
+ if (responseEntity != null) {
try {
- EntityUtils.consume(responeEntity);
+ EntityUtils.consume(responseEntity);
} catch (IOException e) {
// nothing what we can do
}
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_12.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_12.adoc
index 9439734..420f3c9 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_12.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_12.adoc
@@ -49,6 +49,12 @@ with naming pattern `...AsciiDoc` and `...HtmlDoc`.
The XML DSL with `camel-cdi` has removed the deprecated `<proxy>` functionality.
+=== camel-http-common
+
+The method `org.apache.camel.http.common.HttpHelper.readResponseBodyFromInputStream` is renamed to `cacheResponseBodyFromInputStream`,
+because it must cache the response body as it is used with the `PollingConsumer` in `camel-http`,
+that otherwise may fail if the original `InputStream` is closed by the underlying HTTP client.
+
=== camel-jms
The `camel-jms` component now better support Apache Artemis in streaming mode for large messages support,