Author: hiranya
Date: Thu Jul 18 21:40:26 2013
New Revision: 1504674

URL: http://svn.apache.org/r1504674
Log:
Applying the patch for SYNAPSE-847; Getting rid of redundant code to close the 
file input stream. This is taken care of by the FileObject.close() method. Also 
using an AutoCloseInputStream so that the input stream will be closed early if 
Synapse consumes it entirely.

Modified:
    synapse/trunk/java/modules/transports/core/vfs/pom.xml
    
synapse/trunk/java/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java

Modified: synapse/trunk/java/modules/transports/core/vfs/pom.xml
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/vfs/pom.xml?rev=1504674&r1=1504673&r2=1504674&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/core/vfs/pom.xml (original)
+++ synapse/trunk/java/modules/transports/core/vfs/pom.xml Thu Jul 18 21:40:26 
2013
@@ -58,7 +58,7 @@
                             !org.apache.commons.io.output,
                             org.apache.commons.io.output; version=0.0.0,
                             org.apache.commons.vfs2.*; version=0.0.0,
-                                                       org.apache.commons.io; 
version=0.0.0,
+                                                       
org.apache.commons.io.*; version=0.0.0,
                             *; resolution:=optional
                         </Import-Package>
                     </instructions>

Modified: 
synapse/trunk/java/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java?rev=1504674&r1=1504673&r2=1504674&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java
 (original)
+++ 
synapse/trunk/java/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java
 Thu Jul 18 21:40:26 2013
@@ -36,6 +36,7 @@ import org.apache.axis2.transport.base.B
 import org.apache.axis2.transport.base.ManagementSupport;
 import org.apache.axis2.transport.base.threads.WorkerPool;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.input.AutoCloseInputStream;
 import org.apache.commons.vfs2.*;
 import org.apache.commons.vfs2.impl.StandardFileSystemManager;
 
@@ -543,7 +544,7 @@ public class VFSTransportListener extend
                 dataSource = ManagedDataSourceFactory.create(
                         new FileObjectDataSource(file, contentType));
             } else {
-                in = content.getInputStream();
+                in = new AutoCloseInputStream(content.getInputStream());
                 dataSource = null;
             }
             
@@ -563,15 +564,8 @@ public class VFSTransportListener extend
                     null, //* SOAP Action - not applicable *//
                     contentType
                 );
-            }
-            finally {
-                if (in != null) {
-                    try {
-                        in.close();
-                    } catch (IOException ex) {
-                        handleException("Error closing stream", ex);
-                    }
-                } else {
+            } finally {
+                if (dataSource != null) {
                     dataSource.destroy();
                 }
             }
@@ -585,9 +579,10 @@ public class VFSTransportListener extend
             
         } finally {
             try {
+                // As per the Commons-VFS API docs, this will also close the 
underlying
+                // FileContent object and any open streams.
                 file.close();
-            } catch (FileSystemException warn) {
-                log.warn("Cannot close file after processing : " + 
file.getName().getPath(), warn);
+            } catch (FileSystemException ignored) {
             }
         }
     }


Reply via email to