Author: dkulp Date: Tue Jul 28 16:00:34 2009 New Revision: 798581 URL: http://svn.apache.org/viewvc?rev=798581&view=rev Log: Merged revisions 798575 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................ r798575 | dkulp | 2009-07-28 11:48:16 -0400 (Tue, 28 Jul 2009) | 10 lines Merged revisions 798561 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r798561 | dkulp | 2009-07-28 11:26:25 -0400 (Tue, 28 Jul 2009) | 2 lines Update to really allow streaming of mtom attachments with jaxb Also close the underlying stream ........ ................ Modified: cxf/branches/2.1.x-fixes/ (props changed) cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java 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/DelegatingInputStream.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 cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Jul 28 16:00:34 2009 @@ -1,2 +1,2 @@ -/cxf/branches/2.2.x-fixes:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760,774851,774979,775423,776024-776025,776218,776429,776459,777189,777224,777243,777481,777505,777572,777580,780033,780184,780213,780421,780664,780800,780902,780911,781497,781841,782733,782735-782736,783099,783407,784064,784197,785293,785296,785298-785299,785301,785656,786158,786587,786589,786591-786592,786640,787272,787276,787282-787283,787285,787295,787307,787324,7873 67,788824-788825,788827-788828,788830,789423,789429,789707,789709-789710,789712,789721,789905,789908,789910,789912,790295,790646-790647,790651,790654-790655,790659,791948,791950,791952,791955,792276,792288,792291,792992,792995,792998,794402,794404,794735,794797,794799,794803,795161-795162,796300-796301,796598,797449,797452-797453,797460,797463-797464,797521-797522,797584-797585,797645,797652,797701,797884,797886,798348-798350,798574 -/cxf/trunk:782181,782728-782730,783097,783396,784059,784181,784895,785279-785282,785468,786142,786271,786395,786582-786583,786638,786647,787269,787277-787279,787290,787305,787323,787366,788060,788187,788703,788774,788820,789371,789420,789527-789529,789704-789705,789896,789898-789900,790294,790637-790644,791354,791538,791753,791947,792261-792263,792684,792975,792985,794297,794396,794728,794778-794780,794892,795160,796022-796023,796593,796780,797194,797231-797233,797442,797505,797517,797581-797582,797640,797651,797699,797882-797883,798344-798346,798551 +/cxf/branches/2.2.x-fixes:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760,774851,774979,775423,776024-776025,776218,776429,776459,777189,777224,777243,777481,777505,777572,777580,780033,780184,780213,780421,780664,780800,780902,780911,781497,781841,782733,782735-782736,783099,783407,784064,784197,785293,785296,785298-785299,785301,785656,786158,786587,786589,786591-786592,786640,787272,787276,787282-787283,787285,787295,787307,787324,7873 67,788824-788825,788827-788828,788830,789423,789429,789707,789709-789710,789712,789721,789905,789908,789910,789912,790295,790646-790647,790651,790654-790655,790659,791948,791950,791952,791955,792276,792288,792291,792992,792995,792998,794402,794404,794735,794797,794799,794803,795161-795162,796300-796301,796598,797449,797452-797453,797460,797463-797464,797521-797522,797584-797585,797645,797652,797701,797884,797886,798348-798350,798574-798575 +/cxf/trunk:782181,782728-782730,783097,783396,784059,784181,784895,785279-785282,785468,786142,786271,786395,786582-786583,786638,786647,787269,787277-787279,787290,787305,787323,787366,788060,788187,788703,788774,788820,789371,789420,789527-789529,789704-789705,789896,789898-789900,790294,790637-790644,791354,791538,791753,791947,792261-792263,792684,792975,792985,794297,794396,794728,794778-794780,794892,795160,796022-796023,796593,796780,797194,797231-797233,797442,797505,797517,797581-797582,797640,797651,797699,797882-797883,798344-798346,798551,798561 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/AttachmentDataSource.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=798581&r1=798580&r2=798581&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java Tue Jul 28 16:00:34 2009 @@ -31,17 +31,35 @@ public class AttachmentDataSource implements DataSource { private final String ct; - private final CachedOutputStream cache; + private CachedOutputStream cache; + private InputStream ins; + private DelegatingInputStream lastIns; public AttachmentDataSource(String ctParam, InputStream inParam) throws IOException { this.ct = ctParam; - cache = new CachedOutputStream(); - IOUtils.copy(inParam, cache); - cache.lockOutputStream(); + ins = inParam; } + public boolean isCached() { + return cache != null; + } + public void hold() { - cache.holdTempFile(); + try { + if (cache == null) { + cache = new CachedOutputStream(); + IOUtils.copy(ins, cache); + cache.lockOutputStream(); + cache.holdTempFile(); + ins.close(); + ins = null; + if (lastIns != null) { + lastIns.setInputStream(cache.getInputStream()); + } + } + } catch (IOException e) { + //shouldn't happen + } } public void release() { cache.releaseTempFileHold(); @@ -53,9 +71,14 @@ public InputStream getInputStream() { try { - return new DelegatingInputStream(cache.getInputStream()); + if (cache != null) { + return cache.getInputStream(); + } + if (ins instanceof DelegatingInputStream) { + lastIns = (DelegatingInputStream)ins; + } + return ins; } catch (IOException e) { - e.printStackTrace(); return null; } } 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=798581&r1=798580&r2=798581&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 Tue Jul 28 16:00:34 2009 @@ -58,6 +58,8 @@ private int pbAmount = 2048; private PushbackInputStream stream; + private int createCount; + private int closedCount; private byte boundary[]; @@ -122,7 +124,9 @@ throw new RuntimeException(e); } - body = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount)); + body = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount), + this); + createCount++; message.setContent(InputStream.class, body); } } @@ -199,13 +203,15 @@ && !((DelegatingInputStream) body).isClosed()) { cache((DelegatingInputStream) body, true); - message.setContent(InputStream.class, body); } for (Attachment a : attachments.getLoadedAttachments()) { DataSource s = a.getDataHandler().getDataSource(); - if (!(s instanceof AttachmentDataSource)) { - //AttachementDataSource objects are already cached + if (s instanceof AttachmentDataSource) { + if (!((AttachmentDataSource)s).isCached()) { + cache((DelegatingInputStream) s.getInputStream(), false); + } + } else { cache((DelegatingInputStream) s.getInputStream(), false); } } @@ -279,7 +285,9 @@ */ private Attachment createAttachment(InternetHeaders headers) throws IOException { InputStream partStream = - new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount)); + new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount), + this); + createCount++; return AttachmentUtil.createAttachment(partStream, headers); } @@ -290,4 +298,11 @@ public void setLazyLoading(boolean lazyLoading) { this.lazyLoading = lazyLoading; } + + public void markClosed(DelegatingInputStream delegatingInputStream) throws IOException { + closedCount++; + if (closedCount == createCount && !attachments.hasNext()) { + stream.close(); + } + } } Modified: cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java?rev=798581&r1=798580&r2=798581&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java Tue Jul 28 16:00:34 2009 @@ -25,19 +25,24 @@ final class DelegatingInputStream extends InputStream { private InputStream is; + private AttachmentDeserializer deserializer; private boolean isClosed; /** * @param source */ - DelegatingInputStream(InputStream is) { + DelegatingInputStream(InputStream is, AttachmentDeserializer ads) { this.is = is; + deserializer = ads; } @Override public void close() throws IOException { is.close(); isClosed = true; + if (!isClosed) { + deserializer.markClosed(this); + } } public boolean isClosed() { 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=798581&r1=798580&r2=798581&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 Tue Jul 28 16:00:34 2009 @@ -58,6 +58,15 @@ throw new RuntimeException(e); } } + public boolean hasNext() throws IOException { + Attachment a = deserializer.readNext(); + if (a != null) { + attachments.add(a); + return true; + } + return false; + } + public Iterator<Attachment> iterator() { return new Iterator<Attachment>() { 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=798581&r1=798580&r2=798581&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 Tue Jul 28 16:00:34 2009 @@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; import java.io.InputStream; import java.io.PushbackInputStream; import java.util.Collection; @@ -76,11 +75,6 @@ InputStream attIs = a.getDataHandler().getInputStream(); - // We need to cache the InputStream for reusing the AttachmentDataSource - //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream); - assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream); - assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream); - // check the cached output stream ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(attBody, out); @@ -125,11 +119,6 @@ InputStream attIs = a.getDataHandler().getInputStream(); - // We need to cache the InputStream for reusing the AttachmentDataSource - //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream); - assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream); - assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream); - // check the cached output stream ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(attBody, out); @@ -174,12 +163,6 @@ InputStream attIs = a.getDataHandler().getInputStream(); - // We need to cache the InputStream for reusing the AttachmentDataSource - //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream); - assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream); - - assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream); - // check the cached output stream ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(attBody, out); @@ -222,11 +205,6 @@ InputStream attIs = a.getDataHandler().getInputStream(); - // We need to cache the InputStream for reusing the AttachmentDataSource - //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream); - assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream); - assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream); - // check the cached output stream ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(attBody, out); @@ -274,11 +252,12 @@ InputStream attIs = a.getDataHandler().getInputStream(); - // We need to cache the InputStream for reusing the AttachmentDataSource - //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream); - assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream); - assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof FileInputStream); + assertFalse(itr.hasNext()); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + IOUtils.copy(attIs, out); + assertTrue(out.size() > 1000); + } Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java?rev=798581&r1=798580&r2=798581&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java (original) +++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java Tue Jul 28 16:00:34 2009 @@ -51,6 +51,7 @@ import org.apache.cxf.hello_world_jms.HelloWorldServiceRuntimeCorrelationIDDynamicPrefix; import org.apache.cxf.hello_world_jms.HelloWorldServiceRuntimeCorrelationIDStaticPrefix; import org.apache.cxf.hello_world_jms.NoSuchCodeLitFault; +import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.jms_mtom.JMSMTOMPortType; import org.apache.cxf.jms_mtom.JMSMTOMService; import org.apache.cxf.service.model.EndpointInfo; @@ -900,7 +901,8 @@ handler1.value = new DataHandler(fileURL); int size = handler1.value.getInputStream().available(); mtom.testDataHandler(name, handler1); - int size2 = handler1.value.getInputStream().available(); - assertTrue("The response file is not same with the sent file.", size == size2); + + byte bytes[] = IOUtils.readBytesFromStream(handler1.value.getInputStream()); + assertEquals("The response file is not same with the sent file.", size, bytes.length); } } Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=798581&r1=798580&r2=798581&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java (original) +++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Tue Jul 28 16:00:34 2009 @@ -30,11 +30,11 @@ import javax.xml.ws.Holder; import javax.xml.ws.soap.SOAPBinding; -import org.apache.axiom.attachments.utils.IOUtils; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.ClientImpl; +import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.JaxWsClientProxy; @@ -89,7 +89,6 @@ ((BindingProvider)mtomPort).getRequestContext().put("schema-validation-enabled", Boolean.TRUE); - param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream")); Holder<String> name = new Holder<String>("call detail"); mtomPort.testXop(name, param); @@ -97,7 +96,7 @@ assertNotNull(param.value); InputStream in = param.value.getInputStream(); - byte bytes[] = IOUtils.getStreamAsByteArray(in); + byte bytes[] = IOUtils.readBytesFromStream(in); assertEquals(data.length, bytes.length); in.close(); @@ -108,10 +107,9 @@ assertNotNull(param.value); in = param.value.getInputStream(); - bytes = IOUtils.getStreamAsByteArray(in); + bytes = IOUtils.readBytesFromStream(in); assertEquals(data.length, bytes.length); in.close(); - } catch (UndeclaredThrowableException ex) { throw (Exception)ex.getCause(); }
