CAMEL-10492: Allow to configure attachmentMultipartBinding as endpoint option 
to make it easier to turn on.


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

Branch: refs/heads/camel-2.18.x
Commit: 7c89c38fdd1b8a6442a228b1d1f5a65b2f926288
Parents: 2a78bb3
Author: Claus Ibsen <[email protected]>
Authored: Mon Nov 21 10:55:38 2016 +0100
Committer: Claus Ibsen <[email protected]>
Committed: Mon Nov 21 10:56:38 2016 +0100

----------------------------------------------------------------------
 .../ServletComponentConfiguration.java           |  4 ++--
 .../src/main/docs/servlet-component.adoc         |  5 +++--
 .../component/servlet/ServletComponent.java      |  8 +++++++-
 .../camel/component/servlet/ServletEndpoint.java | 19 +++++++++++++++++--
 4 files changed, 29 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7c89c38f/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 add4a67..8137e2d 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,8 @@ 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 servet 
specific
-     * configuration to enable this when using Servlet's.
+     * Exchange. 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/7c89c38f/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 33b337d..27c23e7 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 servet specific configuration to enable this when 
using Servlet's.
+| 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.
 | 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.
@@ -66,7 +66,7 @@ The Servlet component supports 7 options which are listed 
below.
 // component options: END
 
 // endpoint options: START
-The Servlet component supports 21 endpoint options which are listed below:
+The Servlet component supports 22 endpoint options which are listed below:
 
 {% raw %}
 [width="100%",cols="2,1,1m,1m,5",options="header"]
@@ -87,6 +87,7 @@ The Servlet component supports 21 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.
 | 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/7c89c38f/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 0ceee78..4a6c1f4 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
@@ -64,6 +64,7 @@ public class ServletComponent extends HttpCommonComponent 
implements RestConsume
         String httpMethodRestrict = getAndRemoveParameter(parameters, 
"httpMethodRestrict", String.class);
         HeaderFilterStrategy headerFilterStrategy = 
resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", 
HeaderFilterStrategy.class);
         Boolean async = getAndRemoveParameter(parameters, "async", 
Boolean.class);
+        Boolean attachmentMultipartBinding = getAndRemoveParameter(parameters, 
"attachmentMultipartBinding", 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
@@ -117,6 +118,11 @@ public class ServletComponent extends HttpCommonComponent 
implements RestConsume
         if (httpMethodRestrict != null) {
             endpoint.setHttpMethodRestrict(httpMethodRestrict);
         }
+        if (attachmentMultipartBinding != null) {
+            endpoint.setAttachmentMultipartBinding(attachmentMultipartBinding);
+        } else {
+            
endpoint.setAttachmentMultipartBinding(isAttachmentMultipartBinding());
+        }
 
         setProperties(endpoint, parameters);
         return endpoint;
@@ -187,7 +193,7 @@ public class ServletComponent extends HttpCommonComponent 
implements RestConsume
     /**
      * Whether to automatic bind multipart/form-data as attachments on the 
Camel {@link Exchange}.
      * <p/>
-     * This is turn off by default as this may require servet specific 
configuration to enable this when using Servlet's.
+     * 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) {
         this.attachmentMultipartBinding = attachmentMultipartBinding;

http://git-wip-us.apache.org/repos/asf/camel/blob/7c89c38f/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 384a4ec..7a66a95 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
@@ -20,6 +20,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 
 import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.http.common.DefaultHttpBinding;
@@ -41,9 +42,10 @@ public class ServletEndpoint extends HttpCommonEndpoint {
 
     @UriPath(label = "consumer") @Metadata(required = "true")
     private String contextPath;
-
     @UriParam(label = "consumer", defaultValue = "CamelServlet")
     private String servletName;
+    @UriParam(label = "consumer,advanced")
+    private boolean attachmentMultipartBinding;
 
     public ServletEndpoint() {
     }
@@ -63,7 +65,7 @@ public class ServletEndpoint extends HttpCommonEndpoint {
         // make sure we include servlet variant of the http binding
         if (this.binding == null) {
             // is attachment binding enabled?
-            if (getComponent().isAttachmentMultipartBinding()) {
+            if (isAttachmentMultipartBinding()) {
                 this.binding = new AttachmentHttpBinding();
             } else {
                 this.binding = new DefaultHttpBinding();
@@ -109,6 +111,19 @@ public class ServletEndpoint extends HttpCommonEndpoint {
         return servletName;
     }
 
+    public boolean isAttachmentMultipartBinding() {
+        return attachmentMultipartBinding;
+    }
+
+    /**
+     * Whether to automatic bind multipart/form-data as attachments on the 
Camel {@link Exchange}.
+     * <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) {
+        this.attachmentMultipartBinding = attachmentMultipartBinding;
+    }
+
     @Override
     public Producer createProducer() throws Exception {
         throw new UnsupportedOperationException("You cannot create producer 
with servlet endpoint, please consider to use http or http4 endpoint.");

Reply via email to