[ 
https://issues.apache.org/jira/browse/CAMEL-12078?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16539639#comment-16539639
 ] 

ASF GitHub Bot commented on CAMEL-12078:
----------------------------------------

tdudgeon commented on a change in pull request #2185: Failing test for 
CAMEL-12078
URL: https://github.com/apache/camel/pull/2185#discussion_r201582751
 
 

 ##########
 File path: 
components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
 ##########
 @@ -351,6 +351,41 @@ public void unmarshalInlineHeadersNonMimeBodyStream() 
throws UnsupportedEncoding
         assertEquals("This is not a MIME-Multipart", bodyStr);
     }
 
+    @Test
+    public void attachmentReadOnce() throws IOException {
+        String attContentType = "text/plain";
+        String attText = "Attachment Text";
+        InputStream attInputStream = new 
ByteArrayInputStream(attText.getBytes());
+        String attFileName = "Attachment File Name";
+        in.setBody("Body text");
+        in.setHeader(Exchange.CONTENT_TYPE, 
"text/plain;charset=iso8859-1;other-parameter=true");
+        in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Content-Description", "Sample Attachment Data");
+        headers.put("X-AdditionalData", "additional data");
+        CountingByteArrayDataSource attachmentDs = new 
CountingByteArrayDataSource(attInputStream, attContentType);
+        addAttachment(attachmentDs, attFileName, headers);
+        Exchange result = template.send("direct:roundtrip", exchange);
+        Message out = result.getOut();
+        assertEquals("Body text", out.getBody(String.class));
+        assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), 
startsWith("text/plain"));
+        assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
+        assertTrue(out.hasAttachments());
+        assertEquals(1, out.getAttachmentNames().size());
+        assertThat(out.getAttachmentNames(), hasItem(attFileName));
+        Attachment att = out.getAttachmentObject(attFileName);
+        DataHandler dh = att.getDataHandler();
+        assertNotNull(dh);
+        assertEquals(attContentType, dh.getContentType());
+        InputStream is = dh.getInputStream();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        IOHelper.copyAndCloseInput(is, os);
+        assertEquals(attText, new String(os.toByteArray()));
+        assertEquals("Sample Attachment Data", 
att.getHeader("content-description"));
+        assertEquals("additional data", att.getHeader("X-AdditionalData"));
+        assertEquals(1, attachmentDs.readCounts); // Fails - input is read 
twice
 
 Review comment:
   @onderson Not sure what update you want on this. The code does seem to read 
the InputStream twice, and that can cause problems when the stream can't be 
read multiple times.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> MIME-Mutipart DataFormat reads attachment DataSource twice
> ----------------------------------------------------------
>
>                 Key: CAMEL-12078
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12078
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-mail
>    Affects Versions: 2.20.1
>            Reporter: Tim Dudgeon
>            Priority: Minor
>             Fix For: Future
>
>
> As reported on mailing list if an attachment for MIME-Mutipart DataFormat is 
> defined using a DataSource that can only be read once you get an exception.
> http://mail-archives.apache.org/mod_mbox/camel-users/201712.mbox/%3C0e0d4b2e-dc32-c61e-3ccd-7ee14238c485%40gmail.com%3E
> For instance, this happens if the DataSource is created using an InputStream 
> that cannot be read multiple times
> It should be possible to post the data only reading the input a single time.
> I will add a test case shortly.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to