camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r744606 - in /camel/trunk/components/camel-ftp/src: main/java/org/apache/camel/component/file/remote/FtpOperations.java test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java
Date Sun, 15 Feb 2009 03:32:17 GMT
Author: ningjiang
Date: Sun Feb 15 03:32:17 2009
New Revision: 744606

URL: http://svn.apache.org/viewvc?rev=744606&view=rev
Log:
CAMEL-1341 fixed the unit test error of FtpConsumerLocalWorkDirectoryTest

Modified:
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=744606&r1=744605&r2=744606&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Sun Feb 15 03:32:17 2009
@@ -30,6 +30,7 @@
 import org.apache.camel.component.file.GenericFileEndpoint;
 import org.apache.camel.component.file.GenericFileExchange;
 import org.apache.camel.component.file.GenericFileOperationFailedException;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -194,8 +195,8 @@
     }
 
     private boolean retrieveFileToFileInLocalWorkDirectory(String name, GenericFileExchange<FTPFile>
exchange) throws GenericFileOperationFailedException {
-        File temp;
-        File local = new File(endpoint.getLocalWorkDirectory());
+        File temp;        
+        File local = new File(FileUtil.normalizePath(endpoint.getLocalWorkDirectory()));
         OutputStream os;
         try {
             // use relative filename in local work directory
@@ -216,8 +217,9 @@
             if (local.exists()) {
                 if (!local.delete()) {
                     throw new RemoteFileOperationFailedException("Cannot delete existing
local work file: " + local);
-                }
+                }                
             }
+           
 
             // create new temp local work file
             if (!temp.createNewFile()) {
@@ -227,10 +229,10 @@
             // store content as a file in the local work directory in the temp handle
             os = new FileOutputStream(temp);
 
-            // set header with the path to the local work file
+            // set header with the path to the local work file            
             exchange.getIn().setHeader("CamelFileLocalWorkPath", local.getPath());
 
-        } catch (Exception e) {
+        } catch (Exception e) {            
             throw new RemoteFileOperationFailedException("Cannot create new local work file:
" + local);
         }
 
@@ -238,18 +240,21 @@
         try {
             GenericFile<FTPFile> target = exchange.getGenericFile();
             // store the java.io.File handle as the body
-            target.setBody(local);
+            target.setBody(local);            
             result = client.retrieveFile(name, os);
-
-            // rename temp to local after we have retrieved the data
-            if (!temp.renameTo(local)) {
-                throw new RemoteFileOperationFailedException("Cannot rename local work file
from: " + temp + " to: " + local);
-            }
-        } catch (IOException e) {
+            
+        } catch (IOException e) {            
             throw new RemoteFileOperationFailedException(client.getReplyCode(), client.getReplyString(),
e.getMessage(), e);
-        } finally {
+        }  finally {
+            // need to close the stream before rename it
             ObjectHelper.close(os, "retrieve: " + name, LOG);
+        }   
+            
+        // rename temp to local after we have retrieved the data
+        if (!temp.renameTo(local)) {                
+            throw new RemoteFileOperationFailedException("Cannot rename local work file from:
" + temp + " to: " + local);
         }
+        
 
         return result;
     }

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java?rev=744606&r1=744605&r2=744606&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java
Sun Feb 15 03:32:17 2009
@@ -26,6 +26,7 @@
 import org.apache.camel.component.file.NewFileComponent;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.IOConverter;
+import org.apache.camel.util.FileUtil;
 
 /**
  * @version $Revision$
@@ -39,6 +40,7 @@
     @Override
     protected void setUp() throws Exception {
         deleteDirectory("target/lwd");
+        deleteDirectory("target/out");
         super.setUp();
         prepareFtpServer();
     }
@@ -82,8 +84,8 @@
                     public void process(Exchange exchange) throws Exception {
                         File body = exchange.getIn().getBody(File.class);
                         assertNotNull(body);
-                        assertTrue("Local work file should exists", body.exists());
-                        assertEquals("target/lwd/hello.txt", body.getPath());
+                        assertTrue("Local work file should exists", body.exists());     
                  
+                        assertEquals(FileUtil.normalizePath("target/lwd/hello.txt"), body.getPath());
                     }
                 }).to("file://target/out", "mock:result");
             }



Mime
View raw message