Author: dkulp Date: Fri Jun 10 00:51:51 2011 New Revision: 1134156 URL: http://svn.apache.org/viewvc?rev=1134156&view=rev Log: Merged revisions 1134145 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.4.x-fixes
................ r1134145 | dkulp | 2011-06-09 20:42:01 -0400 (Thu, 09 Jun 2011) | 10 lines Merged revisions 1134142 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1134142 | dkulp | 2011-06-09 20:38:46 -0400 (Thu, 09 Jun 2011) | 2 lines [CXF-3582] Fix problems trying to find attachments when reading from the middle of buffers. ........ ................ Added: cxf/branches/2.3.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/cxf3582.data - copied unchanged from r1134145, cxf/branches/2.4.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/cxf3582.data Modified: cxf/branches/2.3.x-fixes/ (props changed) cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java cxf/branches/2.3.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Propchange: cxf/branches/2.3.x-fixes/ ('svn:mergeinfo' removed) Propchange: cxf/branches/2.3.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java?rev=1134156&r1=1134155&r2=1134156&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java (original) +++ cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java Fri Jun 10 00:51:51 2011 @@ -179,7 +179,7 @@ public class MimeBodyPartInputStream ext //boundary matched (may or may not be last mime boundary) int processed = initialI - off; - if ((len - (i + 2)) > 0) { + if ((len - ((i - off) + 2)) > 0) { inStream.unread(buffer, i + 2, len - (i + 2) + off); } return processed; Modified: cxf/branches/2.3.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=1134156&r1=1134155&r2=1134156&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java (original) +++ cxf/branches/2.3.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Fri Jun 10 00:51:51 2011 @@ -495,4 +495,142 @@ public class AttachmentDeserializerTest } } -} \ No newline at end of file + + @Test + public void testCXF3582() throws Exception { + String contentType = "multipart/related; type=\"application/xop+xml\"; " + + "boundary=\"uuid:906fa67b-85f9-4ef5-8e3d-52416022d463\"; " + + "start=\"<[email protected]>\"; start-info=\"text/xml\""; + + + Message message = new MessageImpl(); + message.put(Message.CONTENT_TYPE, contentType); + message.setContent(InputStream.class, getClass().getResourceAsStream("cxf3582.data")); + message.put(AttachmentDeserializer.ATTACHMENT_DIRECTORY, System + .getProperty("java.io.tmpdir")); + message.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, String + .valueOf(AttachmentDeserializer.THRESHOLD)); + + + AttachmentDeserializer ad + = new AttachmentDeserializer(message, + Collections.singletonList("multipart/related")); + + ad.initializeAttachments(); + + String cid = "[email protected]"; + DataSource ds = AttachmentUtil.getAttachmentDataSource(cid, message.getAttachments()); + byte bts[] = new byte[1024]; + InputStream ins = ds.getInputStream(); + int count = ins.read(bts, 0, bts.length); + assertEquals(500, count); + assertEquals(-1, ins.read(new byte[1000], 500, 500)); + + cid = "[email protected]"; + ds = AttachmentUtil.getAttachmentDataSource(cid, message.getAttachments()); + bts = new byte[1024]; + ins = ds.getInputStream(); + count = ins.read(bts, 0, bts.length); + assertEquals(1024, count); + assertEquals(225, ins.read(new byte[1000], 500, 500)); + assertEquals(-1, ins.read(new byte[1000], 500, 500)); + } + + @Test + public void testCXF3582b() throws Exception { + String contentType = "multipart/related; type=\"application/xop+xml\"; " + + "boundary=\"uuid:906fa67b-85f9-4ef5-8e3d-52416022d463\"; " + + "start=\"<[email protected]>\"; start-info=\"text/xml\""; + + + Message message = new MessageImpl(); + message.put(Message.CONTENT_TYPE, contentType); + message.setContent(InputStream.class, getClass().getResourceAsStream("cxf3582.data")); + message.put(AttachmentDeserializer.ATTACHMENT_DIRECTORY, System + .getProperty("java.io.tmpdir")); + message.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, String + .valueOf(AttachmentDeserializer.THRESHOLD)); + + + AttachmentDeserializer ad + = new AttachmentDeserializer(message, + Collections.singletonList("multipart/related")); + + ad.initializeAttachments(); + + String cid = "[email protected]"; + DataSource ds = AttachmentUtil.getAttachmentDataSource(cid, message.getAttachments()); + byte bts[] = new byte[1024]; + InputStream ins = ds.getInputStream(); + int count = 0; + int x = ins.read(bts, 500, 200); + while (x != -1) { + count += x; + x = ins.read(bts, 500, 200); + } + assertEquals(500, count); + assertEquals(-1, ins.read(new byte[1000], 500, 500)); + + cid = "[email protected]"; + ds = AttachmentUtil.getAttachmentDataSource(cid, message.getAttachments()); + bts = new byte[1024]; + ins = ds.getInputStream(); + count = 0; + x = ins.read(bts, 500, 200); + while (x != -1) { + count += x; + x = ins.read(bts, 500, 200); + } + assertEquals(1249, count); + assertEquals(-1, ins.read(new byte[1000], 500, 500)); + } + @Test + public void testCXF3582c() throws Exception { + String contentType = "multipart/related; type=\"application/xop+xml\"; " + + "boundary=\"uuid:906fa67b-85f9-4ef5-8e3d-52416022d463\"; " + + "start=\"<[email protected]>\"; start-info=\"text/xml\""; + + + Message message = new MessageImpl(); + message.put(Message.CONTENT_TYPE, contentType); + message.setContent(InputStream.class, getClass().getResourceAsStream("cxf3582.data")); + message.put(AttachmentDeserializer.ATTACHMENT_DIRECTORY, System + .getProperty("java.io.tmpdir")); + message.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, String + .valueOf(AttachmentDeserializer.THRESHOLD)); + + + AttachmentDeserializer ad + = new AttachmentDeserializer(message, + Collections.singletonList("multipart/related")); + + ad.initializeAttachments(); + + String cid = "[email protected]"; + DataSource ds = AttachmentUtil.getAttachmentDataSource(cid, message.getAttachments()); + byte bts[] = new byte[1024]; + InputStream ins = ds.getInputStream(); + int count = 0; + int x = ins.read(bts, 100, 600); + while (x != -1) { + count += x; + x = ins.read(bts, 100, 600); + } + assertEquals(500, count); + assertEquals(-1, ins.read(new byte[1000], 100, 600)); + + cid = "[email protected]"; + ds = AttachmentUtil.getAttachmentDataSource(cid, message.getAttachments()); + bts = new byte[1024]; + ins = ds.getInputStream(); + count = 0; + x = ins.read(bts, 100, 600); + while (x != -1) { + count += x; + x = ins.read(bts, 100, 600); + } + assertEquals(1249, count); + assertEquals(-1, ins.read(new byte[1000], 100, 600)); + } +} +
