CAMEL-8075 Camel ftp should send a command to check if the connection is broken 
before pulling the files


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9054cee5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9054cee5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9054cee5

Branch: refs/heads/camel-2.14.x
Commit: 9054cee5bb89fefa2b17891aed70198244e3aae7
Parents: e53e97d
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Thu Apr 23 11:15:04 2015 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Thu Apr 23 14:30:51 2015 +0800

----------------------------------------------------------------------
 .../camel/component/file/remote/RemoteFileConsumer.java   | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9054cee5/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
index fb32885..5b4b12c 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
@@ -149,7 +149,15 @@ public abstract class RemoteFileConsumer<T> extends 
GenericFileConsumer<T> {
     }
 
     protected void connectIfNecessary() throws IOException {
-        if (!loggedIn) {
+        // We need to send a noop first to check if the connection is still 
open 
+        boolean isConnected = false;
+        try {
+            isConnected = getOperations().sendNoop();
+        } catch (Exception ex) {
+            // here we just ignore the exception and try to reconnect 
+        }
+        
+        if (!loggedIn || !isConnected) {
             if (log.isDebugEnabled()) {
                 log.debug("Not connected/logged in, connecting to: {}", 
remoteServer());
             }

Reply via email to