Author: dkulp Date: Wed Oct 28 16:03:33 2009 New Revision: 830656 URL: http://svn.apache.org/viewvc?rev=830656&view=rev Log: Merged revisions 830655 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................ r830655 | dkulp | 2009-10-28 12:01:43 -0400 (Wed, 28 Oct 2009) | 9 lines 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.1.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/mimedata2 - copied unchanged from r830655, cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/mimedata2 Modified: cxf/branches/2.1.x-fixes/ (props changed) cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java cxf/branches/2.1.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Oct 28 16:03:33 2009 @@ -1,2 +1,2 @@ -/cxf/branches/2.2.x-fixes:830223 +/cxf/branches/2.2.x-fixes:830223,830655 /cxf/trunk:830196 Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=830656&r1=830655&r2=830656&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java Wed Oct 28 16:03:33 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.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java?rev=830656&r1=830655&r2=830656&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java Wed Oct 28 16:03:33 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.1.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=830656&r1=830655&r2=830656&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Wed Oct 28 16:03:33 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=\"<[email protected]>\"; " + + "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\"; "
