You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by lh...@apache.org on 2008/12/10 20:15:25 UTC

svn commit: r725389 - /servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java

Author: lhein
Date: Wed Dec 10 11:15:25 2008
New Revision: 725389

URL: http://svn.apache.org/viewvc?rev=725389&view=rev
Log:
fixed SM-1624 (help on patching provided by Bhaskar Dabbigodla)

Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java?rev=725389&r1=725388&r2=725389&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java Wed Dec 10 11:15:25 2008
@@ -272,7 +272,7 @@
             }
         });
     }
-
+    
     protected boolean processFileAndDelete(String file) {
         FTPClient ftp = null;
         boolean unlock = true;
@@ -281,7 +281,7 @@
             if (logger.isDebugEnabled()) {
                 logger.debug("Processing file " + file);
             }
-            if (ftp.listFiles(file).length > 0) {
+            if (isFileExistingOnServer(ftp, file)) {
                 // Process the file. If processing fails, an exception should be thrown.
                 processFile(ftp, file);
                 // Processing is successful
@@ -305,6 +305,36 @@
         return unlock;
     }
 
+    /**
+     * checks if file specified exists on server
+     * 
+     * @param ftp       the ftp client
+     * @param file      the full file path
+     * @return          true if found on server
+     */
+    private boolean isFileExistingOnServer(FTPClient ftp, String file) throws IOException {
+        boolean foundFile = false;
+        int lastIndex = file.lastIndexOf("/");
+        String directory = ".";
+        String rawName = file;
+        if (lastIndex > 0) { 
+            directory = file.substring(0, lastIndex);
+            rawName = file.substring(lastIndex + 1);
+        }
+
+        FTPFile[] files = listFiles(ftp, directory);
+        if (files.length > 0) {
+            for (FTPFile f : files) {
+                if (f.getName().equals(rawName)) {
+                    foundFile = true;
+                    break;
+                }
+            }
+        }
+
+        return foundFile;
+    }
+    
     protected void processFile(FTPClient ftp, String file) throws Exception {
         InputStream in = ftp.retrieveFileStream(file);
         InOnly exchange = getExchangeFactory().createInOnlyExchange();