This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit e52425e6b9f70a7f59e5a2b6025330470049f0f0 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Jan 17 10:40:46 2018 +0100 CAMEL-12061: camel-ftp now forces a hard disconnect in case of rollback such as error during scanning files etc, to force a fresh client/login on next poll to mitigate any transient issues in the ftp client. --- .../camel/component/file/remote/FtpOperations.java | 5 +++++ .../camel/component/file/remote/RemoteFileConsumer.java | 16 ++++++++++++++++ .../component/file/remote/RemoteFileOperations.java | 7 +++++++ .../remote/RemoteFilePollingConsumerPollStrategy.java | 6 +++--- .../camel/component/file/remote/SftpOperations.java | 17 ++++++++++++++++- .../org/apache/camel/component/scp/ScpOperations.java | 16 ++++++++++++++-- 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java index 36a7c5d..fba2389 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java @@ -249,6 +249,11 @@ public class FtpOperations implements RemoteFileOperations<FTPFile> { } } + @Override + public void forceDisconnect() throws GenericFileOperationFailedException { + doDisconnect(); + } + protected void doDisconnect() throws GenericFileOperationFailedException { // logout before disconnecting clientActivityListener.onDisconnecting(endpoint.getConfiguration().remoteServerInformation()); 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 483e4aa..a676732 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 @@ -166,6 +166,22 @@ public abstract class RemoteFileConsumer<T> extends GenericFileConsumer<T> { } } + protected void forceDisconnect() { + // eager indicate we are no longer logged in + loggedIn = false; + + // disconnect + try { + if (log.isDebugEnabled()) { + log.debug("Force disconnecting from: {}", remoteServer()); + } + getOperations().forceDisconnect(); + } catch (GenericFileOperationFailedException e) { + // ignore just log a warning + log.warn("Error occurred while disconnecting from " + remoteServer() + " due: " + e.getMessage() + ". This exception will be ignored."); + } + } + protected void recoverableConnectIfNecessary() throws Exception { try { connectIfNecessary(); diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java index 55573cb..7136682 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java @@ -49,6 +49,13 @@ public interface RemoteFileOperations<T> extends GenericFileOperations<T> { void disconnect() throws GenericFileOperationFailedException; /** + * Forces a hard disconnect from the remote server and cause the client to be re-created on next poll. + * + * @throws GenericFileOperationFailedException can be thrown + */ + void forceDisconnect() throws GenericFileOperationFailedException; + + /** * Sends a noop command to the remote server * * @return <tt>true</tt> if the noop was a success, <tt>false</tt> otherwise diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java index fea8be2..85d40cd 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFilePollingConsumerPollStrategy.java @@ -35,12 +35,12 @@ public class RemoteFilePollingConsumerPollStrategy extends DefaultPollingConsume // only try to recover if we are allowed to run if (rfc.isRunAllowed()) { // disconnect from the server to force it to re login at next poll to recover - log.warn("Trying to recover by disconnecting from remote server forcing a re-connect at next poll: " + rfc.remoteServer()); + log.warn("Trying to recover by force disconnecting from remote server and re-connecting at next poll: {}", rfc.remoteServer()); try { - rfc.disconnect(); + rfc.forceDisconnect(); } catch (Throwable t) { // ignore the exception - log.debug("Error occurred during disconnect from: " + rfc.remoteServer() + ". This exception will be ignored.", t); + log.debug("Error occurred during force disconnecting from: " + rfc.remoteServer() + ". This exception will be ignored.", t); } } } diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java index a06ad5c..e6178a9 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java @@ -420,9 +420,24 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> { } } + public synchronized void forceDisconnect() throws GenericFileOperationFailedException { + try { + if (session != null) { + session.disconnect(); + } + if (channel != null) { + channel.disconnect(); + } + } finally { + // ensure these + session = null; + channel = null; + } + } + private void reconnectIfNecessary() { if (!isConnected()) { - connect((RemoteFileConfiguration) endpoint.getConfiguration()); + connect(endpoint.getConfiguration()); } } diff --git a/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java b/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java index 3854f4a..6fdfe0d 100644 --- a/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java +++ b/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java @@ -193,10 +193,22 @@ public class ScpOperations implements RemoteFileOperations<ScpFile> { @Override public void disconnect() throws GenericFileOperationFailedException { - if (isConnected()) { + try { + if (isConnected()) { + session.disconnect(); + } + } finally { + session = null; + } + } + + @Override + public void forceDisconnect() throws GenericFileOperationFailedException { + try { session.disconnect(); + } finally { + session = null; } - session = null; } @Override -- To stop receiving notification emails like this one, please contact "commits@camel.apache.org" <commits@camel.apache.org>.