Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 64905194F5 for ; Thu, 28 Apr 2016 08:28:02 +0000 (UTC) Received: (qmail 77628 invoked by uid 500); 28 Apr 2016 08:28:02 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 77579 invoked by uid 500); 28 Apr 2016 08:28:02 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 77483 invoked by uid 99); 28 Apr 2016 08:28:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Apr 2016 08:28:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AA1ECE00C7; Thu, 28 Apr 2016 08:28:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Thu, 28 Apr 2016 08:28:02 -0000 Message-Id: In-Reply-To: <3c7c489376664029825febb5a0817cbf@git.apache.org> References: <3c7c489376664029825febb5a0817cbf@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] camel git commit: CAMEL-9874: Camel Jetty consumer endpoint incorrectly handles multipart/form-data 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 Authored: Thu Apr 28 10:27:02 2016 +0200 Committer: Claus Ibsen 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 @@ camel-jaxb test + + + com.squareup.okhttp3 + okhttp + ${okclient-version} + junit 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 @@ 1.2.7 1.6.3 20100527_1 + 3.2.0 2.0.6 2.0.6_1 2.4