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 2009/10/28 17:01:43 UTC

svn commit: r830655 - in /cxf/branches/2.2.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/attachment/ rt/core/src/test/java/org/apache/cxf/attachment/

Author: dkulp
Date: Wed Oct 28 16:01:43 2009
New Revision: 830655

URL: http://svn.apache.org/viewvc?rev=830655&view=rev
Log:
Merged revisions 830651 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r830651 | dkulp | 2009-10-28 11:59:32 -0400 (Wed, 28 Oct 2009) | 1 line
  
  [CXF-2503] Patch from William Tam applied
........

Added:
    cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/mimedata2
      - copied unchanged from r830651, cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/mimedata2
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
    cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=830655&r1=830654&r2=830655&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java Wed Oct 28 16:01:43 2009
@@ -23,6 +23,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -219,7 +220,8 @@
             cache((DelegatingInputStream) body, true);
         }
 
-        for (Attachment a : attachments.getLoadedAttachments()) {
+        List<Attachment> atts = new ArrayList<Attachment>(attachments.getLoadedAttachments());
+        for (Attachment a : atts) {
             DataSource s = a.getDataHandler().getDataSource();
             if (s instanceof AttachmentDataSource) {
                 AttachmentDataSource ads = (AttachmentDataSource)s;
@@ -316,7 +318,7 @@
 
     public void markClosed(DelegatingInputStream delegatingInputStream) throws IOException {
         closedCount++;
-        if (closedCount == createCount && !attachments.hasNext()) {
+        if (closedCount == createCount && !attachments.hasNext(false)) {
             int x = stream.read();
             while (x != -1) {
                 x = stream.read();
@@ -325,4 +327,24 @@
             closed = true;
         }
     }
+    /**
+     *  Check for more attachment.
+     *
+     * @return whether there is more attachment or not.  It will not deserialize the next attachment.
+     * @throws IOException
+     */
+    public boolean hasNext() throws IOException {
+        cacheStreamedAttachments();
+        if (closed) {
+            return false;
+        }
+
+        int v = stream.read();
+        if (v == -1) {
+            return false;
+        }
+        stream.unread(v);
+        return true;
+    }
+
 }

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java?rev=830655&r1=830654&r2=830655&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java Wed Oct 28 16:01:43 2009
@@ -58,16 +58,28 @@
             throw new RuntimeException(e);
         }
     }
-    public boolean hasNext() throws IOException {
-        Attachment a = deserializer.readNext();
-        if (a != null) {
-            attachments.add(a);
-            return true;
-        }
-        return false;
+    /**
+     * Check for more attachments by attempting to deserialize the next attachment.
+     *
+     * @param shouldLoadNew if <i>false</i>, the "loaded attachments" List will not be changed.
+     * @return there is more attachment or not
+     * @throws IOException
+     */
+    public boolean hasNext(boolean shouldLoadNew) throws IOException {
+        if (shouldLoadNew) {
+            Attachment a = deserializer.readNext();
+            if (a != null) {
+                attachments.add(a);
+                return true;
+            }
+            return false;
+        } 
+        return deserializer.hasNext();
     }
 
-
+    public boolean hasNext() throws IOException {
+        return hasNext(true);
+    }
     public Iterator<Attachment> iterator() {
         return new Iterator<Attachment>() {
             int current;

Modified: cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=830655&r1=830654&r2=830655&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java (original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Wed Oct 28 16:01:43 2009
@@ -47,6 +47,27 @@
     }
     
     @Test
+    public void testLazyAttachmentCollection() throws Exception {
+        InputStream is = getClass().getResourceAsStream("mimedata2");
+        String ct = "multipart/related; type=\"application/xop+xml\"; "
+                    + "start=\"<so...@xfire.codehaus.org>\"; "
+                    + "start-info=\"text/xml; charset=utf-8\"; "
+                    + "boundary=\"----=_Part_4_701508.1145579811786\"";
+        
+        msg.put(Message.CONTENT_TYPE, ct);
+        msg.setContent(InputStream.class, is);
+        
+        AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);
+        deserializer.initializeAttachments();
+        
+        InputStream attBody = msg.getContent(InputStream.class);
+        assertTrue(attBody != is);
+        assertTrue(attBody instanceof DelegatingInputStream);
+        attBody.close();
+        assertEquals(2, msg.getAttachments().size());
+    }
+    
+    @Test
     public void testDeserializerMtom() throws Exception {
         InputStream is = getClass().getResourceAsStream("mimedata");
         String ct = "multipart/related; type=\"application/xop+xml\"; "