You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/10/06 18:43:24 UTC

svn commit: r702200 - in /servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file: FileComponent.java FilePollerEndpoint.java

Author: gertv
Date: Mon Oct  6 09:43:23 2008
New Revision: 702200

URL: http://svn.apache.org/viewvc?rev=702200&view=rev
Log:
SMX4-121: IOException - could not delete file on Windows

Modified:
    servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FileComponent.java
    servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java

Modified: servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FileComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FileComponent.java?rev=702200&r1=702199&r2=702200&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FileComponent.java (original)
+++ servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FileComponent.java Mon Oct  6 09:43:23 2008
@@ -34,7 +34,10 @@
  * @version $Revision$
  * @org.apache.xbean.XBean element="component" description="a JBI component that interacts with the file system. It hosts endpoints that reads data from and writes data to the file system."
  */
+@SuppressWarnings("unchecked")
 public class FileComponent extends DefaultComponent {
+    
+    public static final String FILE_PROPERTY = "org.apache.servicemix.file";
 
     private FileEndpointType[] endpoints;
 

Modified: servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java?rev=702200&r1=702199&r2=702200&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java Mon Oct  6 09:43:23 2008
@@ -62,7 +62,7 @@
     private File archive;
     private FileMarshaler marshaler = new DefaultFileMarshaler();
     private LockManager lockManager;
-    private ConcurrentMap<String, File> openExchanges;
+    private ConcurrentMap<String, InputStream> openExchanges;
 
     public FilePollerEndpoint() {
     }
@@ -83,7 +83,7 @@
         super.start();
         
         // create the openExchanges map
-        this.openExchanges = new ConcurrentHashMap<String, File>();
+        this.openExchanges = new ConcurrentHashMap<String, InputStream>();
     }
     
     public void poll() throws Exception {
@@ -154,10 +154,10 @@
     }
 
     /**
-            * Specifies a class that implements the locking strategy used by 
-            * the endpoint. This class must be an implementation of the 
-            * <code>org.apache.servicemix.locks.LockManager</code> interface.
-            *
+     * Specifies a class that implements the locking strategy used by 
+     * the endpoint. This class must be an implementation of the 
+     * <code>org.apache.servicemix.locks.LockManager</code> interface.
+     *
      * @param lockManager the <code>LockManager</code> implementation to use
      * @org.apache.xbean.Property description="the bean defining the class implementing the file locking strategy"
      */
@@ -337,16 +337,18 @@
         }
     }
 
-    protected void processFile(File aFile) throws Exception {
-        InputStream in = null;
-        String name = aFile.getCanonicalPath();
-        in = new BufferedInputStream(new FileInputStream(aFile));
+    protected void processFile(File file) throws Exception {
+        InputStream stream = new BufferedInputStream(new FileInputStream(file));
         InOnly exchange = getExchangeFactory().createInOnlyExchange();
         configureExchangeTarget(exchange);
         NormalizedMessage message = exchange.createMessage();
         exchange.setInMessage(message);
-        marshaler.readMessage(exchange, message, in, name);
-        this.openExchanges.put(exchange.getExchangeId(), aFile);
+        marshaler.readMessage(exchange, message, stream, file.getCanonicalPath());
+
+        //sending the file itself along as a message property and holding on to the stream we opened
+        exchange.getInMessage().setProperty(FileComponent.FILE_PROPERTY, file);
+        this.openExchanges.put(exchange.getExchangeId(), stream);
+        
         send(exchange);
     }
 
@@ -357,9 +359,16 @@
     public void process(MessageExchange exchange) throws Exception {
         // check for done or error
         if (this.openExchanges.containsKey(exchange.getExchangeId())) {
-            File aFile = this.openExchanges.get(exchange.getExchangeId());
+            InputStream stream = this.openExchanges.get(exchange.getExchangeId());
+            File aFile = (File) exchange.getMessage("in").getProperty(FileComponent.FILE_PROPERTY);
+            
+            if (aFile == null) {
+                throw new JBIException("Property org.apache.servicemix.file was removed from the exchange -- unable to delete/archive the file");
+            }
 
             logger.debug("Releasing " + aFile.getAbsolutePath());
+            //first try to close the stream 
+            stream.close();
             try {
                 // check for state
                 if (exchange.getStatus() == ExchangeStatus.DONE) {