camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-9874: Camel Jetty consumer endpoint incorrectly handles multipart/form-data
Date Thu, 28 Apr 2016 08:28:02 GMT
CAMEL-9874: Camel Jetty consumer endpoint incorrectly handles multipart/form-data


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

Branch: refs/heads/camel-2.17.x
Commit: 28317b2ad7be507ddade36429f68926dcfc045a7
Parents: 53630bd
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Apr 28 10:27:02 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Apr 28 10:27:52 2016 +0200

----------------------------------------------------------------------
 components/camel-jetty9/pom.xml                 |  6 ++
 .../component/jetty9/AttachmentHttpBinding.java |  5 --
 .../jetty/HttpBridgeMultipartRouteTest.java     |  2 +-
 .../jetty/MultiPartFormOkHttpTest.java          | 76 ++++++++++++++++++++
 .../component/jetty/MultiPartFormTest.java      |  2 +-
 .../MultiPartFormWithCustomFilterTest.java      |  4 +-
 parent/pom.xml                                  |  1 +
 7 files changed, 87 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/28317b2a/components/camel-jetty9/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/pom.xml b/components/camel-jetty9/pom.xml
index 9a5e517..8b55bd8 100644
--- a/components/camel-jetty9/pom.xml
+++ b/components/camel-jetty9/pom.xml
@@ -127,6 +127,12 @@
       <artifactId>camel-jaxb</artifactId>
       <scope>test</scope>
     </dependency>
+    <!-- testing with ok http client -->
+    <dependency>
+      <groupId>com.squareup.okhttp3</groupId>
+      <artifactId>okhttp</artifactId>
+      <version>${okclient-version}</version>
+    </dependency>
 
     <dependency>
       <groupId>junit</groupId>

http://git-wip-us.apache.org/repos/asf/camel/blob/28317b2a/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 f798714..4d88670 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
@@ -44,11 +44,6 @@ final class AttachmentHttpBinding extends DefaultHttpBinding {
             try {
                 parts = parser.getParts();
                 for (Part part : parts) {
-                    String contentType = part.getContentType();
-                    if (!contentType.startsWith("application/octet-stream")) {
-                        continue;
-                    }
-
                     DataSource ds = new PartDataSource(part);
                     message.addAttachment(part.getName(), new DataHandler(ds));
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/28317b2a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
index e7797c7..ac09f30 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java
@@ -65,7 +65,7 @@ public class HttpBridgeMultipartRouteTest extends BaseJettyTest {
         assertEquals(body, responseBody);
         
         String numAttachments = method.getResponseHeader("numAttachments").getValue();
-        assertEquals(numAttachments, "1");
+        assertEquals(numAttachments, "2");
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/28317b2a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormOkHttpTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormOkHttpTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormOkHttpTest.java
new file mode 100644
index 0000000..1221cc9
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormOkHttpTest.java
@@ -0,0 +1,76 @@
+/**
+ * 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.jetty;
+
+import java.io.InputStream;
+
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class MultiPartFormOkHttpTest extends BaseJettyTest {
+
+    private Request createMultipartRequest() throws Exception {
+        MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");
+        RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition:
form-data; name=\"test\"\r\n\r\nsome data here\r\n-----011000010111000001101001--");
+        Request request = new Request.Builder()
+            .url("http://localhost:" + getPort() + "/test")
+            .post(body)
+            .addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
+            .addHeader("cache-control", "no-cache")
+            .addHeader("postman-token", "a9fd95b6-04b9-ea7a-687e-ff828ea00774")
+            .build();
+        return request;
+    }
+
+    @Test
+    public void testSendMultiPartFormFromOkHttpClient() throws Exception {
+        OkHttpClient client = new OkHttpClient();
+        Request request = createMultipartRequest();
+        Response response = client.newCall(request).execute();
+
+        assertEquals(200, response.code());
+        assertEquals("Thanks", response.body().string());
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("jetty://http://localhost:{{port}}/test").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        assertTrue("Should have attachment", exchange.getIn().hasAttachments());
+
+                        InputStream is = exchange.getIn().getAttachment("test").getInputStream();
+                        assertNotNull(is);
+                        String data = exchange.getContext().getTypeConverter().convertTo(String.class,
exchange, is);
+                        assertNotNull("Should have data", data);
+                        assertEquals("some data here", data);
+
+                        exchange.getOut().setBody("Thanks");
+                    }
+                });
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/28317b2a/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 6b3e87f..407cb47 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
@@ -82,7 +82,7 @@ public class MultiPartFormTest extends BaseJettyTest {
 
                     public void process(Exchange exchange) throws Exception {
                         Message in = exchange.getIn();
-                        assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
+                        assertEquals("Get a wrong attachement size", 2, in.getAttachments().size());
                         // The file name is attachment id
                         DataHandler data = in.getAttachment("NOTICE.txt");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/28317b2a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java
index eef3b20..1307da7 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java
@@ -113,7 +113,7 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest {
                 from("jetty://http://localhost:{{port}}/test?multipartFilterRef=myMultipartFilter").process(new
Processor() {
                     public void process(Exchange exchange) throws Exception {
                         Message in = exchange.getIn();
-                        assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
+                        assertEquals("Get a wrong attachement size", 2, in.getAttachments().size());
                         // The file name is attachment id
                         DataHandler data = in.getAttachment("NOTICE.txt");
 
@@ -137,7 +137,7 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest {
                 from("jetty://http://localhost:{{port}}/test2?multipartFilterRef=myMultipartFilter&enableMultipartFilter=false").process(new
Processor() {
                     public void process(Exchange exchange) throws Exception {
                         Message in = exchange.getIn();
-                        assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
+                        assertEquals("Get a wrong attachement size", 2, in.getAttachments().size());
                         DataHandler data = in.getAttachment("NOTICE.txt");
 
                         assertNotNull("Should get the DataHandle NOTICE.txt", data);

http://git-wip-us.apache.org/repos/asf/camel/blob/28317b2a/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index f8a2774..08a47f4 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -424,6 +424,7 @@
     <openwebbeans1-version>1.2.7</openwebbeans1-version>
     <openwebbeans-version>1.6.3</openwebbeans-version>
     <oauth-provider-bundle-version>20100527_1</oauth-provider-bundle-version>
+    <okclient-version>3.2.0</okclient-version>
     <olingo2-version>2.0.6</olingo2-version>
     <olingo-odata2-core-bundle-version>2.0.6_1</olingo-odata2-core-bundle-version>
     <olingo2-gson-version>2.4</olingo2-gson-version>


Mime
View raw message