You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/11/06 12:56:34 UTC

svn commit: r1198345 - in /camel/branches/camel-2.8.x: ./ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/ components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/

Author: davsclaus
Date: Sun Nov  6 11:56:33 2011
New Revision: 1198345

URL: http://svn.apache.org/viewvc?rev=1198345&view=rev
Log:
CAMEL-4010: FTP consumer should process UoW synchronously to ensure done work is done with same thread, as the FTP libraries is not thread safe.

Added:
    camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpAsyncProcessTest.java
      - copied unchanged from r1198340, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpAsyncProcessTest.java
Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
    camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov  6 11:56:33 2011
@@ -1 +1 @@
-/camel/trunk:1186106,1186625,1186772,1187221,1187485,1187882,1187893,1188070-1188085,1188642,1188674,1188879,1188881,1189139,1189600,1189681,1189693,1189737,1190212-1190213,1190246,1190303,1195317,1195616,1196210,1197450,1197933,1197948,1198199,1198338
+/camel/trunk:1186106,1186625,1186772,1187221,1187485,1187882,1187893,1188070-1188085,1188642,1188674,1188879,1188881,1189139,1189600,1189681,1189693,1189737,1190212-1190213,1190246,1190303,1195317,1195616,1196210,1197450,1197933,1197948,1198199,1198338,1198340

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1198345&r1=1198344&r2=1198345&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Sun Nov  6 11:56:33 2011
@@ -193,11 +193,13 @@ public class FtpOperations implements Re
     public void disconnect() throws GenericFileOperationFailedException {
         // logout before disconnecting
         try {
+            log.trace("Client logout");
             client.logout();
         } catch (IOException e) {
             throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
         } finally {
             try {
+                log.trace("Client disconnect");
                 client.disconnect();
             } catch (IOException e) {
                 throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
@@ -228,6 +230,7 @@ public class FtpOperations implements Re
             }
 
             // delete the file
+            log.trace("Client deleteFile: {}", target);
             result = client.deleteFile(target);
 
             // change back to previous directory
@@ -321,6 +324,7 @@ public class FtpOperations implements Re
                 remoteName = FileUtil.stripPath(name);
             }
 
+            log.trace("Client retrieveFile: {}", remoteName);
             result = client.retrieveFile(remoteName, os);
 
             // change back to current directory
@@ -403,6 +407,7 @@ public class FtpOperations implements Re
                 remoteName = FileUtil.stripPath(name);
             }
 
+            log.trace("Client retrieveFile: {}", remoteName);
             result = client.retrieveFile(remoteName, os);
 
             // change back to current directory
@@ -496,8 +501,10 @@ public class FtpOperations implements Re
         try {
             is = exchange.getIn().getMandatoryBody(InputStream.class);
             if (endpoint.getFileExist() == GenericFileExist.Append) {
+                log.trace("Client appendFile: {}", targetName);
                 return client.appendFile(targetName, is);
             } else {
+                log.trace("Client storeFile: {}", targetName);
                 return client.storeFile(targetName, is);
             }
         } catch (IOException e) {
@@ -542,7 +549,7 @@ public class FtpOperations implements Re
     }
 
     protected boolean fastExistsFile(String name) throws GenericFileOperationFailedException {
-        log.trace("fastexistsFile({})", name);
+        log.trace("fastExistsFile({})", name);
         try {
             String[] names = client.listNames(name);
             if (names == null) {

Modified: camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java?rev=1198345&r1=1198344&r2=1198345&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java Sun Nov  6 11:56:33 2011
@@ -18,6 +18,7 @@ package org.apache.camel.component.file.
 
 import java.io.IOException;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.file.GenericFileConsumer;
@@ -86,6 +87,14 @@ public abstract class RemoteFileConsumer
     }
 
     @Override
+    protected void processExchange(Exchange exchange) {
+        // mark the exchange to be processed synchronously as the ftp client is not thread safe
+        // and we must execute the callbacks in the same thread as this consumer
+        exchange.setProperty(Exchange.UNIT_OF_WORK_PROCESS_SYNC, Boolean.TRUE);
+        super.processExchange(exchange);
+    }
+
+    @Override
     protected void doStop() throws Exception {
         super.doStop();
         disconnect();