Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 84918 invoked from network); 12 Aug 2008 18:21:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Aug 2008 18:21:12 -0000 Received: (qmail 51694 invoked by uid 500); 12 Aug 2008 18:21:11 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 51623 invoked by uid 500); 12 Aug 2008 18:21:11 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 51614 invoked by uid 99); 12 Aug 2008 18:21:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Aug 2008 11:21:11 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Aug 2008 18:20:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DE36523889C0; Tue, 12 Aug 2008 11:20:21 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r685253 - in /cxf/trunk: api/src/main/java/org/apache/cxf/io/ rt/core/src/main/java/org/apache/cxf/attachment/ systests/src/test/java/org/apache/cxf/systest/mtom/ Date: Tue, 12 Aug 2008 18:20:20 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080812182021.DE36523889C0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Tue Aug 12 11:20:19 2008 New Revision: 685253 URL: http://svn.apache.org/viewvc?rev=685253&view=rev Log: [CXF-1743] Fix attachment caching to make sure temp files are deleted properly Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=685253&r1=685252&r2=685253&view=diff ============================================================================== --- cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original) +++ cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Tue Aug 12 11:20:19 2008 @@ -64,6 +64,7 @@ } } + protected boolean outputLocked; protected OutputStream currentStream; private long threshold = DEFAULT_THRESHOLD; @@ -145,6 +146,17 @@ } + /** + * Locks the output stream to prevent additional writes, but maintains + * a pointer to it so an InputStream can be obtained + * @throws IOException + */ + public void lockOutputStream() throws IOException { + currentStream.flush(); + outputLocked = true; + streamList.remove(currentStream); + } + public void close() throws IOException { currentStream.flush(); if (null != callbacks) { @@ -152,7 +164,6 @@ cb.onClose(this); } } - doClose(); currentStream.close(); maybeDeleteTempFile(currentStream); @@ -205,6 +216,7 @@ } } currentStream = out; + outputLocked = false; } public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException { @@ -331,30 +343,36 @@ } public void write(byte[] b, int off, int len) throws IOException { - onWrite(); - this.totalLength += len; - if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) { - createFileOutputStream(); + if (!outputLocked) { + onWrite(); + this.totalLength += len; + if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) { + createFileOutputStream(); + } + currentStream.write(b, off, len); } - currentStream.write(b, off, len); } public void write(byte[] b) throws IOException { - onWrite(); - this.totalLength += b.length; - if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) { - createFileOutputStream(); + if (!outputLocked) { + onWrite(); + this.totalLength += b.length; + if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) { + createFileOutputStream(); + } + currentStream.write(b); } - currentStream.write(b); } public void write(int b) throws IOException { - onWrite(); - this.totalLength++; - if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) { - createFileOutputStream(); + if (!outputLocked) { + onWrite(); + this.totalLength++; + if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) { + createFileOutputStream(); + } + currentStream.write(b); } - currentStream.write(b); } private void createFileOutputStream() throws IOException { Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=685253&r1=685252&r2=685253&view=diff ============================================================================== --- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java (original) +++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java Tue Aug 12 11:20:19 2008 @@ -37,6 +37,7 @@ this.ct = ctParam; cache = new CachedOutputStream(); IOUtils.copy(inParam, cache); + cache.lockOutputStream(); } public String getContentType() { Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=685253&r1=685252&r2=685253&view=diff ============================================================================== --- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java (original) +++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java Tue Aug 12 11:20:19 2008 @@ -212,7 +212,10 @@ for (Attachment a : attachments.getLoadedAttachments()) { DataSource s = a.getDataHandler().getDataSource(); - cache((DelegatingInputStream) s.getInputStream(), false); + if (!(s instanceof AttachmentDataSource)) { + //AttachementDataSource objects are already cached + cache((DelegatingInputStream) s.getInputStream(), false); + } } } @@ -222,11 +225,13 @@ } loaded.add(input); CachedOutputStream out = null; + InputStream origIn = input.getInputStream(); try { out = new CachedOutputStream(); setStreamedAttachmentProperties(out); IOUtils.copy(input, out); input.setInputStream(out.getInputStream()); + origIn.close(); } finally { if (out != null) { out.close(); Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=685253&r1=685252&r2=685253&view=diff ============================================================================== --- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java (original) +++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Tue Aug 12 11:20:19 2008 @@ -59,7 +59,7 @@ @BeforeClass public static void startServers() throws Exception { TestUtilities.setKeepAliveSystemProperty(false); - assertTrue("server did not launch correctly", launchServer(Server.class)); + assertTrue("server did not launch correctly", launchServer(Server.class, true)); } @AfterClass @@ -88,19 +88,27 @@ TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true, true); try { InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl"); - long fileSize = 0; + int fileSize = 0; for (int i = pre.read(); i != -1; i = pre.read()) { fileSize++; } Holder param = new Holder(); - byte[] data = new byte[(int)fileSize]; - this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data); - + + int count = 50; + byte[] data = new byte[fileSize * count]; + for (int x = 0; x < count; x++) { + this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, + fileSize * x, + fileSize); + } + param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream")); Holder name = new Holder("call detail"); mtomPort.testXop(name, param); assertEquals("name unchanged", "return detail + call detail", name.value); assertNotNull(param.value); + param.value.getInputStream().close(); + } catch (UndeclaredThrowableException ex) { throw (Exception)ex.getCause(); }