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/05/03 11:09:53 UTC

[1/2] camel git commit: CAMEL-9633: camel-serlvet has option to turn on multipart-form binding to attachments. You may need to do app server specific configuration to enable it on the app server to make it work, and hence its default disabled in camel-se

Repository: camel
Updated Branches:
  refs/heads/master bf47f40da -> 55813f73f


CAMEL-9633: camel-serlvet has option to turn on multipart-form binding to attachments. You may need to do app server specific configuration to enable it on the app server to make it work, and hence its default disabled in camel-servlet.


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

Branch: refs/heads/master
Commit: 55813f73f4a245e938ee24f5b4e69f108183a4fe
Parents: bf0f638
Author: Claus Ibsen <da...@apache.org>
Authored: Tue May 3 11:09:26 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue May 3 11:09:44 2016 +0200

----------------------------------------------------------------------
 .../servlet/AttachmentHttpBinding.java          | 82 ++++++++++++++++++++
 .../component/servlet/ServletComponent.java     | 15 ++++
 .../component/servlet/ServletEndpoint.java      | 38 +++++++++
 .../servlet/ServletAsyncArquillianTest.java     |  5 --
 4 files changed, 135 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/55813f73/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/AttachmentHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/AttachmentHttpBinding.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/AttachmentHttpBinding.java
new file mode 100644
index 0000000..084e1a3
--- /dev/null
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/AttachmentHttpBinding.java
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.servlet;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.http.common.DefaultHttpBinding;
+import org.apache.camel.http.common.HttpMessage;
+
+/**
+ * To handle attachments with Servlet.
+ * <p/>
+ * This implementation is needed to deal with attachments when using Servlet.
+ */
+final class AttachmentHttpBinding extends DefaultHttpBinding {
+
+    AttachmentHttpBinding() {
+    }
+
+    @Override
+    protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
+        try {
+            Collection<Part> parts = request.getParts();
+            for (Part part : parts) {
+                DataSource ds = new PartDataSource(part);
+                message.addAttachment(part.getName(), new DataHandler(ds));
+            }
+        } catch (Exception e) {
+            throw new RuntimeCamelException("Cannot populate attachments", e);
+        }
+    }
+
+    final class PartDataSource implements DataSource {
+        private final Part part;
+
+        PartDataSource(Part part) {
+            this.part = part;
+        }
+
+        @Override
+        public OutputStream getOutputStream() throws IOException {
+            return null;
+        }
+
+        @Override
+        public String getName() {
+            return part.getName();
+        }
+
+        @Override
+        public InputStream getInputStream() throws IOException {
+            return part.getInputStream();
+        }
+
+        @Override
+        public String getContentType() {
+            return part.getContentType();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/55813f73/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 161c275..2332154 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
@@ -24,6 +24,7 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.http.common.HttpBinding;
 import org.apache.camel.http.common.HttpCommonComponent;
@@ -41,6 +42,7 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
 
     private String servletName = "CamelServlet";
     private HttpRegistry httpRegistry;
+    private boolean attachmentMultipartBinding;
 
     public ServletComponent() {
         super(ServletEndpoint.class);
@@ -178,6 +180,19 @@ public class ServletComponent extends HttpCommonComponent implements RestConsume
         this.httpRegistry = httpRegistry;
     }
 
+    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 servet specific configuration to enable this when using Servlet's.
+     */
+    public void setAttachmentMultipartBinding(boolean attachmentMultipartBinding) {
+        this.attachmentMultipartBinding = attachmentMultipartBinding;
+    }
+
     @Override
     public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
                                    String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters) throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/55813f73/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 5beefc3..384a4ec 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
@@ -22,6 +22,8 @@ import java.net.URISyntaxException;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.http.common.DefaultHttpBinding;
+import org.apache.camel.http.common.HttpBinding;
 import org.apache.camel.http.common.HttpCommonEndpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
@@ -35,6 +37,8 @@ import org.apache.camel.spi.UriPath;
         syntax = "servlet:contextPath", consumerOnly = true, consumerClass = ServletConsumer.class, label = "http")
 public class ServletEndpoint extends HttpCommonEndpoint {
 
+    private HttpBinding binding;
+
     @UriPath(label = "consumer") @Metadata(required = "true")
     private String contextPath;
 
@@ -49,6 +53,40 @@ public class ServletEndpoint extends HttpCommonEndpoint {
         this.contextPath = httpUri.getPath();
     }
 
+    @Override
+    public ServletComponent getComponent() {
+        return (ServletComponent) super.getComponent();
+    }
+
+    @Override
+    public HttpBinding getHttpBinding() {
+        // make sure we include servlet variant of the http binding
+        if (this.binding == null) {
+            // is attachment binding enabled?
+            if (getComponent().isAttachmentMultipartBinding()) {
+                this.binding = new AttachmentHttpBinding();
+            } else {
+                this.binding = new DefaultHttpBinding();
+            }
+            this.binding.setTransferException(isTransferException());
+            if (getComponent() != null) {
+                this.binding.setAllowJavaSerializedObject(getComponent().isAllowJavaSerializedObject());
+            }
+            this.binding.setHeaderFilterStrategy(getHeaderFilterStrategy());
+            this.binding.setEagerCheckContentAvailable(isEagerCheckContentAvailable());
+            this.binding.setMapHttpMessageBody(isMapHttpMessageBody());
+            this.binding.setMapHttpMessageHeaders(isMapHttpMessageHeaders());
+            this.binding.setMapHttpMessageFormUrlEncodedBody(isMapHttpMessageFormUrlEncodedBody());
+        }
+        return this.binding;
+    }
+
+    @Override
+    public void setHttpBinding(HttpBinding binding) {
+        super.setHttpBinding(binding);
+        this.binding = binding;
+    }
+
     public String getContextPath() {
         return contextPath;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/55813f73/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletAsyncArquillianTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletAsyncArquillianTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletAsyncArquillianTest.java
index 8d50058..7c1a877 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletAsyncArquillianTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletAsyncArquillianTest.java
@@ -32,11 +32,6 @@ import org.junit.runner.RunWith;
 import static com.jayway.restassured.RestAssured.given;
 import static org.hamcrest.CoreMatchers.equalTo;
 
-
-/**
- * @author arnaud.deprez
- * @since 18/04/16
- */
 @RunWith(Arquillian.class)
 public class ServletAsyncArquillianTest {
 


[2/2] camel git commit: CAMEL-8854: Allow to set sendServerVersio non the component level of jetty.

Posted by da...@apache.org.
CAMEL-8854: Allow to set sendServerVersio non the component level of jetty.


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

Branch: refs/heads/master
Commit: bf0f638120cb4d84bcd69b5844511612356d2281
Parents: bf47f40
Author: Claus Ibsen <da...@apache.org>
Authored: Tue May 3 10:29:08 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue May 3 11:09:44 2016 +0200

----------------------------------------------------------------------
 .../camel/component/jetty/JettyHttpComponent.java  | 17 +++++++++++++++++
 components/camel-jetty9/src/main/docs/jetty.adoc   |  5 ++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bf0f6381/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index 40dbfcf..5367479 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -55,6 +55,7 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.RestApiConsumerFactory;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestConsumerFactory;
+import org.apache.camel.spi.UriParam;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.HostUtils;
 import org.apache.camel.util.IntrospectionSupport;
@@ -129,6 +130,7 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
     protected String proxyHost;
     protected ErrorHandler errorHandler;
     private Integer proxyPort;
+    private boolean sendServerVersion = true;
 
     public JettyHttpComponent() {
         super(JettyHttpEndpoint.class);
@@ -289,6 +291,7 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
         if (httpClient != null) {
             endpoint.setHttpClient(httpClient);
         }
+        endpoint.setSendServerVersion(isSendServerVersion());
 
         setProperties(endpoint, parameters);
         return endpoint;
@@ -987,6 +990,20 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
         this.proxyPort = proxyPort;
     }
 
+    public boolean isSendServerVersion() {
+        return sendServerVersion;
+    }
+
+    /**
+     * If the option is true, jetty will send the server header with the jetty version information to the client which sends the request.
+     * NOTE please make sure there is no any other camel-jetty endpoint is share the same port, otherwise this option may not work as expected.
+     */
+    @Metadata(description = "If the option is true, jetty server will send the date header to the client which sends the request."
+            + " NOTE please make sure there is no any other camel-jetty endpoint is share the same port, otherwise this option may not work as expected.")
+    public void setSendServerVersion(boolean sendServerVersion) {
+        this.sendServerVersion = sendServerVersion;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/camel/blob/bf0f6381/components/camel-jetty9/src/main/docs/jetty.adoc
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/main/docs/jetty.adoc b/components/camel-jetty9/src/main/docs/jetty.adoc
index e498ce6..e0416ab 100644
--- a/components/camel-jetty9/src/main/docs/jetty.adoc
+++ b/components/camel-jetty9/src/main/docs/jetty.adoc
@@ -50,8 +50,9 @@ Options
 ^^^^^^^
 
 
+
 // component options: START
-The Jetty 9 component supports 29 options which are listed below.
+The Jetty 9 component supports 30 options which are listed below.
 
 
 
@@ -85,6 +86,7 @@ The Jetty 9 component supports 29 options which are listed below.
 | responseHeaderSize | Integer | Allows to configure a custom value of the response header size on the Jetty connectors.
 | proxyHost | String | To use a http proxy to configure the hostname.
 | proxyPort | Integer | To use a http proxy to configure the port number.
+| sendServerVersion | boolean | If the option is true jetty server will send the date header to the client which sends the request. NOTE please make sure there is no any other camel-jetty endpoint is share the same port otherwise this option may not work as expected.
 | 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.
 | headerFilterStrategy | HeaderFilterStrategy | To use a custom HeaderFilterStrategy to filter header to and from Camel message.
 |=======================================================================
@@ -92,6 +94,7 @@ The Jetty 9 component supports 29 options which are listed below.
 
 
 
+
 // endpoint options: START
 The Jetty 9 component supports 52 endpoint options which are listed below: