You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2011/06/10 02:38:46 UTC

svn commit: r1134142 - in /cxf/trunk/rt/core/src: main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java test/java/org/apache/cxf/attachment/cxf3582.data

Author: dkulp
Date: Fri Jun 10 00:38:46 2011
New Revision: 1134142

URL: http://svn.apache.org/viewvc?rev=1134142&view=rev
Log:
[CXF-3582] Fix problems trying to find attachments when reading from the
middle of buffers.

Added:
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/cxf3582.data
Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java?rev=1134142&r1=1134141&r2=1134142&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java Fri Jun 10 00:38:46 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/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=1134142&r1=1134141&r2=1134142&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java (original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Fri Jun 10 00:38:46 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=\"<ro...@cxf.apache.org>\"; 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 = "1a66bb35-67fc-4e89-9f33-48af417bf9fe-1@apache.org";
+        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 = "1a66bb35-67fc-4e89-9f33-48af417bf9fe-2@apache.org";
+        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=\"<ro...@cxf.apache.org>\"; 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 = "1a66bb35-67fc-4e89-9f33-48af417bf9fe-1@apache.org";
+        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 = "1a66bb35-67fc-4e89-9f33-48af417bf9fe-2@apache.org";
+        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=\"<ro...@cxf.apache.org>\"; 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 = "1a66bb35-67fc-4e89-9f33-48af417bf9fe-1@apache.org";
+        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 = "1a66bb35-67fc-4e89-9f33-48af417bf9fe-2@apache.org";
+        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));
+    }
+}
+

Added: cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/cxf3582.data
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/cxf3582.data?rev=1134142&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/cxf3582.data (added)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/cxf3582.data Fri Jun 10 00:38:46 2011
@@ -0,0 +1,40 @@
+POST /jaxws-mtom/hello HTTP/1.1
+Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:906fa67b-85f9-4ef5-8e3d-52416022d463"; start="<ro...@cxf.apache.org>"; start-info="text/xml"
+Accept: */*
+SOAPAction: ""
+User-Agent: Apache CXF ${project.version}
+Cache-Control: no-cache
+Pragma: no-cache
+Host: localhost:9091
+Connection: keep-alive
+Content-Length: 2815
+
+
+
+--uuid:906fa67b-85f9-4ef5-8e3d-52416022d463
+Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
+Content-Transfer-Encoding: binary
+Content-ID: <ro...@cxf.apache.org>
+
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Detail xmlns="http://apache.org/camel/cxf/mtom_feature/types"><photo><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:1a66bb35-67fc-4e89-9f33-48af417bf9fe-1@apache.org"/></photo><image><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:1a66bb35-67fc-4e89-9f33-48af417bf9fe-2@apache.org"/></image></Detail></soap:Body></soap:Envelope>
+--uuid:906fa67b-85f9-4ef5-8e3d-52416022d463
+Content-Type: application/octet-stream
+Content-Transfer-Encoding: binary
+Content-ID: <1a...@apache.org>
+
+0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abc
+--uuid:906fa67b-85f9-4ef5-8e3d-52416022d463
+Content-Type: image/jpeg
+Content-Transfer-Encoding: binary
+Content-ID: <1a...@apache.org>
+
+......JFIF.............C..............
+..
................. $.' ",#..(7),01444.'9=82<.342...C........

.2!.!22222222222222222222222222222222222222222222222222......'.).."......................................
+.....................}........!1A..Qa."q.2....#B...R..$3br..
+.....%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz........................................................................................................
+.....................w.......!1..AQ.aq."2...B.....#3R..br.
+.$4.%.....&'()*56789:CDEFGHIJSTUVWXYZcdefghi
+jstuvwxyz....................................................................................?.....U......;YV.b.w".$r.<.K..
+........@}?...S.(.?.!.........j...v..q*.....m#..A4..d.)...;o.C.C.i.a".....5 ...K..(..l`s...hg.`......W;oe...owi x.... ...J.1;T.."....;WMo.Eswwh."MlWx`0C....9.....FE...iUA$...>.ek.....ze.V.B..XP".........QX>2...Z...C...R............._....!..w7P.Q..5.....]r...I........?.!........k..WR..:t..>....$'.........<.c..
+NJ:.....K.y.F}.2..n..<.D..f.L.S.39U#.B....l........,|.....{..}+....A.1,wO..;...,R.m.U.X...s..i.J.P.......H.I..+m(..B 8b...1.Z.V..i<<..mi...Y.....?.......X>3...Z...C...R..L.;.;Q......Ye.M..J>.......R6.'7?k.tO?......ns...3.(....b|...G...r..tg...G........w.....j....qh.....H......+...P...
+--uuid:906fa67b-85f9-4ef5-8e3d-52416022d463--