Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-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 B629F100B4 for ; Mon, 10 Mar 2014 17:50:47 +0000 (UTC) Received: (qmail 83578 invoked by uid 500); 10 Mar 2014 17:50:45 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 83471 invoked by uid 500); 10 Mar 2014 17:50:44 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 83464 invoked by uid 99); 10 Mar 2014 17:50:42 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Mar 2014 17:50:42 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 65BC493CC8B; Mon, 10 Mar 2014 17:50:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <8f3d4001290145fba536267af11e9d75@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: Adding a JAX-RS multipart test with a minor update to Attachment Date: Mon, 10 Mar 2014 17:50:42 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/master 10570db97 -> 79fb92a5c Adding a JAX-RS multipart test with a minor update to Attachment Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/79fb92a5 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/79fb92a5 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/79fb92a5 Branch: refs/heads/master Commit: 79fb92a5c892a189963d1fefae63f968eb14f857 Parents: 10570db Author: Sergey Beryozkin Authored: Mon Mar 10 17:50:20 2014 +0000 Committer: Sergey Beryozkin Committed: Mon Mar 10 17:50:20 2014 +0000 ---------------------------------------------------------------------- .../cxf/jaxrs/ext/multipart/Attachment.java | 5 ++ .../cxf/systest/jaxrs/JAXRSMultipartTest.java | 51 ++++++++++++++++++++ 2 files changed, 56 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/79fb92a5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java index 18ab5b6..aaeacd0 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java @@ -78,6 +78,11 @@ public class Attachment implements Transferable { this(id, new DataHandler(ds), headers); } + public Attachment(MultivaluedMap headers, Object object) { + this.headers = headers; + this.object = object; + } + public Attachment(InputStream is, MultivaluedMap headers) { this(headers.getFirst("Content-ID"), new DataHandler(new InputStreamDataSource(is, headers.getFirst("Content-Type"))), http://git-wip-us.apache.org/repos/asf/cxf/blob/79fb92a5/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java index f8ddff7..e6af254 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java @@ -496,6 +496,57 @@ public class JAXRSMultipartTest extends AbstractBusClientServerTestBase { assertNotNull(params.get("start")); } + @Test + public void testAddBookJaxbJsonImageWebClientRelated2() throws Exception { + String address = "http://localhost:" + PORT + "/bookstore/books/jaxbimagejson"; + WebClient client = WebClient.create(address); + WebClient.getConfig(client).getOutInterceptors().add(new LoggingOutInterceptor()); + WebClient.getConfig(client).getInInterceptors().add(new LoggingInInterceptor()); + client.type("multipart/mixed").accept("multipart/mixed"); + + Book jaxb = new Book("jaxb", 1L); + Book json = new Book("json", 2L); + InputStream is1 = + getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"); + Map objects = new LinkedHashMap(); + + MultivaluedMap headers = new MetadataMap(); + headers.putSingle("Content-Type", "application/xml"); + headers.putSingle("Content-ID", "theroot"); + headers.putSingle("Content-Transfer-Encoding", "customxml"); + Attachment attJaxb = new Attachment(headers, jaxb); + + headers = new MetadataMap(); + headers.putSingle("Content-Type", "application/json"); + headers.putSingle("Content-ID", "thejson"); + headers.putSingle("Content-Transfer-Encoding", "customjson"); + Attachment attJson = new Attachment(headers, json); + + headers = new MetadataMap(); + headers.putSingle("Content-Type", "application/octet-stream"); + headers.putSingle("Content-ID", "theimage"); + headers.putSingle("Content-Transfer-Encoding", "customstream"); + Attachment attIs = new Attachment(headers, is1); + + objects.put(MediaType.APPLICATION_XML, attJaxb); + objects.put(MediaType.APPLICATION_JSON, attJson); + objects.put(MediaType.APPLICATION_OCTET_STREAM, attIs); + + Collection coll = client.postAndGetCollection(objects, Attachment.class); + List result = new ArrayList(coll); + Book jaxb2 = readBookFromInputStream(result.get(0).getDataHandler().getInputStream()); + assertEquals("jaxb", jaxb2.getName()); + assertEquals(1L, jaxb2.getId()); + Book json2 = readJSONBookFromInputStream(result.get(1).getDataHandler().getInputStream()); + assertEquals("json", json2.getName()); + assertEquals(2L, json2.getId()); + InputStream is2 = result.get(2).getDataHandler().getInputStream(); + byte[] image1 = IOUtils.readBytesFromStream( + getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg")); + byte[] image2 = IOUtils.readBytesFromStream(is2); + assertTrue(Arrays.equals(image1, image2)); + } + private Map doTestAddBookJaxbJsonImageWebClient(String multipartType) throws Exception { String address = "http://localhost:" + PORT + "/bookstore/books/jaxbjsonimage"; WebClient client = WebClient.create(address);