cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
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 GMT
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<DataHandler> param = new Holder<DataHandler>();
-            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<String> name = new Holder<String>("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();
         }



Mime
View raw message