CAMEL-8821 Support to disable the stream caching in camel-servlet from the 
camel context

Conflicts:
        
components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java

Conflicts:
        
components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java


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

Branch: refs/heads/camel-2.14.x
Commit: 7eb4e0a12864853c98fc9371a107121c11cf7e23
Parents: 920429b
Author: Willem Jiang <[email protected]>
Authored: Sun May 31 11:10:42 2015 +0800
Committer: Willem Jiang <[email protected]>
Committed: Sun May 31 17:21:47 2015 +0800

----------------------------------------------------------------------
 .../component/http/DefaultHttpBinding.java      | 22 ++++++++++----------
 .../camel/component/http/helper/HttpHelper.java | 10 +++++++--
 2 files changed, 19 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7eb4e0a1/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 49b9a47..ba154dd 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
@@ -52,7 +52,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Binding between {@link HttpMessage} and {@link HttpServletResponse}.
  *
- * @version 
+ * @version
  */
 public class DefaultHttpBinding implements HttpBinding {
 
@@ -77,12 +77,12 @@ public class DefaultHttpBinding implements HttpBinding {
 
     public void readRequest(HttpServletRequest request, HttpMessage message) {
         LOG.trace("readRequest {}", request);
-        
+
         // lets force a parse of the body and headers
         message.getBody();
         // populate the headers from the request
         Map<String, Object> headers = message.getHeaders();
-        
+
         //apply the headerFilterStrategy
         Enumeration<?> names = request.getHeaderNames();
         while (names.hasMoreElements()) {
@@ -99,7 +99,7 @@ public class DefaultHttpBinding implements HttpBinding {
                 HttpHelper.appendHeader(headers, name, extracted);
             }
         }
-                
+
         if (request.getCharacterEncoding() != null) {
             headers.put(Exchange.HTTP_CHARACTER_ENCODING, 
request.getCharacterEncoding());
             message.getExchange().setProperty(Exchange.CHARSET_NAME, 
request.getCharacterEncoding());
@@ -110,7 +110,7 @@ public class DefaultHttpBinding implements HttpBinding {
         } catch (Exception e) {
             throw new RuntimeCamelException("Cannot read request parameters 
due " + e.getMessage(), e);
         }
-        
+
         Object body = message.getBody();
         // reset the stream cache if the body is the instance of StreamCache
         if (body instanceof StreamCache) {
@@ -146,7 +146,7 @@ public class DefaultHttpBinding implements HttpBinding {
                 throw new RuntimeCamelException("Cannot deserialize body to 
Java object", e);
             }
         }
-        
+
         populateAttachments(request, message);
     }
 
@@ -172,7 +172,7 @@ public class DefaultHttpBinding implements HttpBinding {
 
         LOG.trace("HTTP method {} with Content-Type {}", request.getMethod(), 
request.getContentType());
         Boolean flag = message.getHeader(Exchange.SKIP_WWW_FORM_URLENCODED, 
Boolean.class);
-        boolean skipWwwFormUrlEncoding =  flag != null ? flag : false; 
+        boolean skipWwwFormUrlEncoding =  flag != null ? flag : false;
         if (request.getMethod().equals("POST") && request.getContentType() != 
null
                 && 
request.getContentType().startsWith(HttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED)
                 && !skipWwwFormUrlEncoding) {
@@ -199,7 +199,7 @@ public class DefaultHttpBinding implements HttpBinding {
             }
         }
     }
-    
+
     protected void populateAttachments(HttpServletRequest request, HttpMessage 
message) {
         // check if there is multipart files, if so will put it into 
DataHandler
         Enumeration<?> names = request.getAttributeNames();
@@ -236,7 +236,7 @@ public class DefaultHttpBinding implements HttpBinding {
         if (request.getHeader(Exchange.CONTENT_ENCODING) != null) {
             String contentEncoding = 
request.getHeader(Exchange.CONTENT_ENCODING, String.class);
             response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding);
-        }        
+        }
         if (checkChunked(response, response.getExchange())) {
             response.setHeader(Exchange.TRANSFER_ENCODING, "chunked");
         }
@@ -300,7 +300,7 @@ public class DefaultHttpBinding implements HttpBinding {
             }
         }
     }
-    
+
     protected boolean isText(String contentType) {
         if (contentType != null) {
             String temp = contentType.toLowerCase();
@@ -310,7 +310,7 @@ public class DefaultHttpBinding implements HttpBinding {
         }
         return false;
     }
-    
+
     protected int copyStream(InputStream is, OutputStream os, int bufferSize) 
throws IOException {
         try {
             // copy stream, and must flush on each write as etc Jetty has 
better performance when

http://git-wip-us.apache.org/repos/asf/camel/blob/7eb4e0a1/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 dade973..ecd66c7 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
@@ -40,6 +40,7 @@ import org.apache.camel.component.http.HttpMethods;
 import org.apache.camel.component.http.HttpServletUrlRewrite;
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.converter.stream.CachedOutputStream;
+import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
@@ -160,9 +161,14 @@ public final class HttpHelper {
         if (is == null) {
             return null;
         }
-
+        boolean disableStreamCaching = false;
+        // Just take the consideration of the setting of Camel Context 
StreamCaching
+        if (exchange.getContext() instanceof DefaultCamelContext) {
+            DefaultCamelContext context = (DefaultCamelContext) 
exchange.getContext();
+            disableStreamCaching = !context.isStreamCaching();
+        }
         // 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)) {
+        if (exchange.getProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, 
disableStreamCaching, Boolean.class)) {
             return is;
         } else {
             CachedOutputStream cos = new CachedOutputStream(exchange);

Reply via email to