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 2016/11/29 08:57:12 UTC

camel git commit: CAMEL-10492: Automatic turn of stream caching if using attachment binding mode for camel-servlet as otherwise the attachments are not working.

Repository: camel
Updated Branches:
  refs/heads/master d47addd7f -> 3ac821873


CAMEL-10492: Automatic turn of stream caching if using attachment binding mode for camel-servlet as otherwise the attachments are not working.


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

Branch: refs/heads/master
Commit: 3ac821873bf07a1aca775d8d52a46e06663de663
Parents: d47addd
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Nov 29 09:57:04 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Nov 29 09:57:04 2016 +0100

----------------------------------------------------------------------
 .../ServletComponentConfiguration.java          |  7 +++++--
 .../src/main/docs/servlet-component.adoc        |  4 ++--
 .../component/servlet/ServletComponent.java     | 22 ++++++++++++++++++++
 .../component/servlet/ServletEndpoint.java      |  3 +++
 4 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3ac82187/components-starter/camel-servlet-starter/src/main/java/org/apache/camel/component/servlet/springboot/ServletComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/components-starter/camel-servlet-starter/src/main/java/org/apache/camel/component/servlet/springboot/ServletComponentConfiguration.java b/components-starter/camel-servlet-starter/src/main/java/org/apache/camel/component/servlet/springboot/ServletComponentConfiguration.java
index 8137e2d..95cdf88 100644
--- a/components-starter/camel-servlet-starter/src/main/java/org/apache/camel/component/servlet/springboot/ServletComponentConfiguration.java
+++ b/components-starter/camel-servlet-starter/src/main/java/org/apache/camel/component/servlet/springboot/ServletComponentConfiguration.java
@@ -43,8 +43,11 @@ public class ServletComponentConfiguration {
     private HttpRegistry httpRegistry;
     /**
      * Whether to automatic bind multipart/form-data as attachments on the Camel
-     * Exchange. This is turn off by default as this may require servlet
-     * specific configuration to enable this when using Servlet's.
+     * Exchange. The options attachmentMultipartBinding=true and
+     * disableStreamCache=false cannot work together. Remove disableStreamCache
+     * to use AttachmentMultipartBinding. This is turn off by default as this
+     * may require servlet specific configuration to enable this when using
+     * Servlet's.
      */
     private Boolean attachmentMultipartBinding;
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/3ac82187/components/camel-servlet/src/main/docs/servlet-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/docs/servlet-component.adoc b/components/camel-servlet/src/main/docs/servlet-component.adoc
index d4f17ba..c13599c 100644
--- a/components/camel-servlet/src/main/docs/servlet-component.adoc
+++ b/components/camel-servlet/src/main/docs/servlet-component.adoc
@@ -56,7 +56,7 @@ The Servlet component supports 7 options which are listed below.
 | Name | Java Type | Description
 | servletName | String | Default name of servlet to use. The default name is CamelServlet.
 | httpRegistry | HttpRegistry | To use a custom org.apache.camel.component.servlet.HttpRegistry.
-| attachmentMultipartBinding | boolean | Whether to automatic bind multipart/form-data as attachments on the Camel Exchange. This is turn off by default as this may require servlet specific configuration to enable this when using Servlet's.
+| attachmentMultipartBinding | boolean | Whether to automatic bind multipart/form-data as attachments on the Camel Exchange. The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together. Remove disableStreamCache to use AttachmentMultipartBinding. This is turn off by default as this may require servlet specific configuration to enable this when using Servlet's.
 | httpBinding | HttpBinding | To use a custom HttpBinding to control the mapping between Camel message and HttpClient.
 | httpConfiguration | HttpConfiguration | To use the shared HttpConfiguration as base configuration.
 | allowJavaSerializedObject | boolean | Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.
@@ -87,7 +87,7 @@ The Servlet component supports 22 endpoint options which are listed below:
 | servletName | consumer | CamelServlet | String | Name of the servlet to use
 | traceEnabled | consumer | false | boolean | Specifies whether to enable HTTP TRACE for this Servlet consumer. By default TRACE is turned off.
 | transferException | consumer | false | boolean | If enabled and an Exchange failed processing on the consumer side and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type. On the producer side the exception will be deserialized and thrown as is instead of the HttpOperationFailedException. The caused exception is required to be serialized. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.
-| attachmentMultipartBinding | consumer (advanced) | false | boolean | Whether to automatic bind multipart/form-data as attachments on the Camel Exchange. This is turn off by default as this may require servlet specific configuration to enable this when using Servlet's.
+| attachmentMultipartBinding | consumer (advanced) | false | boolean | Whether to automatic bind multipart/form-data as attachments on the Camel Exchange. The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together. Remove disableStreamCache to use AttachmentMultipartBinding. This is turn off by default as this may require servlet specific configuration to enable this when using Servlet's.
 | exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
 | exchangePattern | consumer (advanced) |  | ExchangePattern | Sets the exchange pattern when the consumer creates an exchange.
 | mapHttpMessageBody | advanced | true | boolean | If this option is true then IN exchange Body of the exchange will be mapped to HTTP body. Setting this to false will avoid the HTTP mapping.

http://git-wip-us.apache.org/repos/asf/camel/blob/3ac82187/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
index 4a6c1f4..a04cf5a 100644
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
@@ -37,9 +37,13 @@ import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ServletComponent extends HttpCommonComponent implements RestConsumerFactory, RestApiConsumerFactory {
 
+    private static final Logger LOG = LoggerFactory.getLogger(ServletComponent.class);
+
     private String servletName = "CamelServlet";
     private HttpRegistry httpRegistry;
     private boolean attachmentMultipartBinding;
@@ -65,6 +69,7 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
         HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
         Boolean async = getAndRemoveParameter(parameters, "async", Boolean.class);
         Boolean attachmentMultipartBinding = getAndRemoveParameter(parameters, "attachmentMultipartBinding", Boolean.class);
+        Boolean disableStreamCache = getAndRemoveParameter(parameters, "disableStreamCache", Boolean.class);
 
         if (lenientContextPath()) {
             // the uri must have a leading slash for the context-path matching to work with servlet, and it can be something people
@@ -123,6 +128,20 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
         } else {
             endpoint.setAttachmentMultipartBinding(isAttachmentMultipartBinding());
         }
+        if (disableStreamCache != null) {
+            endpoint.setDisableStreamCache(disableStreamCache);
+        }
+
+        // turn off stream caching if in attachment mode
+        if (endpoint.isAttachmentMultipartBinding()) {
+            if (disableStreamCache == null) {
+                // disableStreamCache not explict configured so we can automatic change it
+                LOG.info("Disabling stream caching as attachmentMultipartBinding is enabled");
+                endpoint.setDisableStreamCache(true);
+            } else if (!disableStreamCache) {
+                throw new IllegalArgumentException("The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together. Remove disableStreamCache to use AttachmentMultipartBinding");
+            }
+        }
 
         setProperties(endpoint, parameters);
         return endpoint;
@@ -193,6 +212,9 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
     /**
      * Whether to automatic bind multipart/form-data as attachments on the Camel {@link Exchange}.
      * <p/>
+     * The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together.
+     * Remove disableStreamCache to use AttachmentMultipartBinding.
+     * <p/>
      * This is turn off by default as this may require servlet specific configuration to enable this when using Servlet's.
      */
     public void setAttachmentMultipartBinding(boolean attachmentMultipartBinding) {

http://git-wip-us.apache.org/repos/asf/camel/blob/3ac82187/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java
index 7a66a95..9fdd32c 100644
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java
@@ -118,6 +118,9 @@ public class ServletEndpoint extends HttpCommonEndpoint {
     /**
      * Whether to automatic bind multipart/form-data as attachments on the Camel {@link Exchange}.
      * <p/>
+     * The options attachmentMultipartBinding=true and disableStreamCache=false cannot work together.
+     * Remove disableStreamCache to use AttachmentMultipartBinding.
+     * <p/>
      * This is turn off by default as this may require servlet specific configuration to enable this when using Servlet's.
      */
     public void setAttachmentMultipartBinding(boolean attachmentMultipartBinding) {