camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-10399 camel-jetty - consumer should not load attachment payload
Date Thu, 27 Oct 2016 06:27:14 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 24e9a9d7d -> 28adde1a6


CAMEL-10399 camel-jetty - consumer should not load attachment payload


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

Branch: refs/heads/camel-2.18.x
Commit: 28adde1a6c39bce30e18cd40e5a5f70f801930c5
Parents: 24e9a9d
Author: Tomohisa Igarashi <tm.igarashi@gmail.com>
Authored: Thu Oct 27 00:08:03 2016 +0900
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Oct 27 08:26:53 2016 +0200

----------------------------------------------------------------------
 .../component/jetty9/AttachmentHttpBinding.java | 42 ++++++++++++++++++++
 .../component/jetty/MultiPartFormTest.java      |  6 +++
 2 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/28adde1a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/AttachmentHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/AttachmentHttpBinding.java
b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/AttachmentHttpBinding.java
index 293dd70..7c51839 100644
--- a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/AttachmentHttpBinding.java
+++ b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/AttachmentHttpBinding.java
@@ -20,6 +20,10 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.activation.DataHandler;
 import javax.activation.DataSource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.Part;
@@ -27,9 +31,12 @@ import javax.servlet.http.Part;
 import org.apache.camel.Attachment;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.http.common.DefaultHttpBinding;
+import org.apache.camel.http.common.HttpHelper;
 import org.apache.camel.http.common.HttpMessage;
 import org.apache.camel.impl.DefaultAttachment;
 import org.eclipse.jetty.util.MultiPartInputStreamParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * To handle attachments with Jetty 9.
@@ -37,6 +44,7 @@ import org.eclipse.jetty.util.MultiPartInputStreamParser;
  * This implementation is needed to deal with attachments when using Jetty 9.
  */
 final class AttachmentHttpBinding extends DefaultHttpBinding {
+    private static final Logger LOG = LoggerFactory.getLogger(AttachmentHttpBinding.class);
 
     AttachmentHttpBinding() {
     }
@@ -64,6 +72,40 @@ final class AttachmentHttpBinding extends DefaultHttpBinding {
             }
         }
     }
+
+    protected void populateRequestParameters(HttpServletRequest request, HttpMessage message)
throws Exception {
+        //we populate the http request parameters without checking the request method
+        Map<String, Object> headers = message.getHeaders();
+        Enumeration<?> names = request.getParameterNames();
+        while (names.hasMoreElements()) {
+            String name = (String)names.nextElement();
+            if (message.getAttachment(name) != null) {
+                DataHandler dh = message.getAttachment(name);
+                Object value = dh;
+                if (dh.getContentType() == null || dh.getContentType().startsWith("text/plain"))
{
+                    value = request.getParameter(name);
+                }
+                if (getHeaderFilterStrategy() != null
+                    && !getHeaderFilterStrategy().applyFilterToExternalHeaders(name,
value, message.getExchange())) {
+                    HttpHelper.appendHeader(headers, name, value);
+                }
+                continue;
+            }
+
+            // there may be multiple values for the same name
+            String[] values = request.getParameterValues(name);
+            LOG.trace("HTTP parameter {} = {}", name, values);
+
+            if (values != null) {
+                for (String value : values) {
+                    if (getHeaderFilterStrategy() != null
+                        && !getHeaderFilterStrategy().applyFilterToExternalHeaders(name,
value, message.getExchange())) {
+                        HttpHelper.appendHeader(headers, name, value);
+                    }
+                }
+            }
+        }
+    }
     
     final class PartDataSource implements DataSource {
         private final Part part;

http://git-wip-us.apache.org/repos/asf/camel/blob/28adde1a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
index 407cb47..715207d 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
@@ -102,6 +102,12 @@ public class MultiPartFormTest extends BaseJettyTest {
 
                         // The other form date can be get from the message
                         // header
+
+                        // For binary attachment, header should also be populated by DataHandler
but not payload
+                        Object header = in.getHeader("NOTICE.txt");
+                        assertEquals(DataHandler.class, header.getClass());
+                        assertEquals(data, header);
+
                         exchange.getOut().setBody(in.getHeader("comment"));
                     }
 


Mime
View raw message