You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2009/06/30 16:31:52 UTC

svn commit: r789759 - in /camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote: FtpOperations.java SftpOperations.java

Author: hadrian
Date: Tue Jun 30 14:31:52 2009
New Revision: 789759

URL: http://svn.apache.org/viewvc?rev=789759&view=rev
Log:
CAMEL-1078.  Prepare for removal of GenericFileExchange.

Modified:
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.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=789759&r1=789758&r2=789759&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 Tue Jun 30 14:31:52 2009
@@ -27,6 +27,7 @@
 import java.util.List;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.component.file.FileComponent;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.file.GenericFileEndpoint;
 import org.apache.camel.component.file.GenericFileExchange;
@@ -183,7 +184,7 @@
         }
     }
 
-    public boolean retrieveFile(String name, GenericFileExchange<FTPFile> exchange) throws GenericFileOperationFailedException {
+    public boolean retrieveFile(String name, Exchange exchange) throws GenericFileOperationFailedException {
         if (ObjectHelper.isNotEmpty(endpoint.getLocalWorkDirectory())) {
             // local work directory is configured so we should store file content as files in this local directory
             return retrieveFileToFileInLocalWorkDirectory(name, exchange);
@@ -193,11 +194,12 @@
         }
     }
 
-    private boolean retrieveFileToStreamInBody(String name, GenericFileExchange<FTPFile> exchange) throws GenericFileOperationFailedException {
+    private boolean retrieveFileToStreamInBody(String name, Exchange exchange) throws GenericFileOperationFailedException {
         OutputStream os = null;
         try {
             os = new ByteArrayOutputStream();
-            GenericFile<FTPFile> target = exchange.getGenericFile();
+            GenericFile<FTPFile> target = (GenericFile<FTPFile>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+            ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
             target.setBody(os);
             return client.retrieveFile(name, os);
         } catch (IOException e) {
@@ -207,13 +209,15 @@
         }
     }
 
-    private boolean retrieveFileToFileInLocalWorkDirectory(String name, GenericFileExchange<FTPFile> exchange) throws GenericFileOperationFailedException {
+    private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exchange) throws GenericFileOperationFailedException {
         File temp;        
         File local = new File(FileUtil.normalizePath(endpoint.getLocalWorkDirectory()));
         OutputStream os;
         try {
             // use relative filename in local work directory
-            String relativeName = exchange.getGenericFile().getRelativeFilePath();
+            GenericFile<FTPFile> target = (GenericFile<FTPFile>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+            ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
+            String relativeName = target.getRelativeFilePath();
             
             temp = new File(local, relativeName + ".inprogress");
             local = new File(local, relativeName);
@@ -232,7 +236,6 @@
                     throw new GenericFileOperationFailedException("Cannot delete existing local work file: " + local);
                 }                
             }
-           
 
             // create new temp local work file
             if (!temp.createNewFile()) {
@@ -251,7 +254,7 @@
 
         boolean result;
         try {
-            GenericFile<FTPFile> target = exchange.getGenericFile();
+            GenericFile<FTPFile> target = (GenericFile<FTPFile>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
             // store the java.io.File handle as the body
             target.setBody(local);            
             result = client.retrieveFile(name, os);
@@ -272,7 +275,7 @@
         return result;
     }
 
-    public boolean storeFile(String name, GenericFileExchange<FTPFile> exchange) throws GenericFileOperationFailedException {
+    public boolean storeFile(String name, Exchange exchange) throws GenericFileOperationFailedException {
 
         // if an existing file already exsists what should we do?
         if (endpoint.getFileExist() == GenericFileExist.Ignore || endpoint.getFileExist() == GenericFileExist.Fail) {
@@ -380,5 +383,4 @@
 
         return success;
     }
-
 }

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=789759&r1=789758&r2=789759&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java Tue Jun 30 14:31:52 2009
@@ -35,9 +35,9 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.component.file.FileComponent;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.file.GenericFileEndpoint;
-import org.apache.camel.component.file.GenericFileExchange;
 import org.apache.camel.component.file.GenericFileExist;
 import org.apache.camel.component.file.GenericFileOperationFailedException;
 import org.apache.camel.util.ExchangeHelper;
@@ -277,7 +277,7 @@
         }
     }
 
-    public boolean retrieveFile(String name, GenericFileExchange<ChannelSftp.LsEntry> exchange) throws GenericFileOperationFailedException {
+    public boolean retrieveFile(String name, Exchange exchange) throws GenericFileOperationFailedException {
         if (ObjectHelper.isNotEmpty(endpoint.getLocalWorkDirectory())) {
             // local work directory is configured so we should store file content as files in this local directory
             return retrieveFileToFileInLocalWorkDirectory(name, exchange);
@@ -287,9 +287,11 @@
         }
     }
 
-    private boolean retrieveFileToStreamInBody(String name, GenericFileExchange<ChannelSftp.LsEntry> exchange) throws GenericFileOperationFailedException {
+    private boolean retrieveFileToStreamInBody(String name, Exchange exchange) throws GenericFileOperationFailedException {
         try {
-            GenericFile<ChannelSftp.LsEntry> target = exchange.getGenericFile();
+            GenericFile<ChannelSftp.LsEntry> target = 
+                (GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+            ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
             OutputStream os = new ByteArrayOutputStream();
             target.setBody(os);
             channel.get(name, os);
@@ -299,13 +301,16 @@
         }
     }
 
-    private boolean retrieveFileToFileInLocalWorkDirectory(String name, GenericFileExchange<ChannelSftp.LsEntry> exchange) throws GenericFileOperationFailedException {
+    private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exchange) throws GenericFileOperationFailedException {
         File temp;
         File local = new File(endpoint.getLocalWorkDirectory());
         OutputStream os;
+        GenericFile<ChannelSftp.LsEntry> file = 
+            (GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+        ObjectHelper.notNull(file, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
         try {
             // use relative filename in local work directory
-            String relativeName = exchange.getGenericFile().getRelativeFilePath();
+            String relativeName = file.getRelativeFilePath();
 
             temp = new File(local, relativeName + ".inprogress");
             local = new File(local, relativeName);
@@ -335,16 +340,13 @@
 
             // set header with the path to the local work file
             exchange.getIn().setHeader(Exchange.FILE_LOCAL_WORK_PATH, local.getPath());
-
-
         } catch (Exception e) {
             throw new GenericFileOperationFailedException("Cannot create new local work file: " + local);
         }
 
         try {
-            GenericFile<ChannelSftp.LsEntry> target = exchange.getGenericFile();
             // store the java.io.File handle as the body
-            target.setBody(local);
+            file.setBody(local);
             channel.get(name, os);
 
             // rename temp to local after we have retrieved the data
@@ -360,7 +362,7 @@
         return true;
     }
 
-    public boolean storeFile(String name, GenericFileExchange<ChannelSftp.LsEntry> exchange) throws GenericFileOperationFailedException {
+    public boolean storeFile(String name, Exchange exchange) throws GenericFileOperationFailedException {
         // if an existing file already exsists what should we do?
         if (endpoint.getFileExist() == GenericFileExist.Ignore || endpoint.getFileExist() == GenericFileExist.Fail) {
             boolean existFile = existFile(name);