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
The following commit(s) were added to refs/heads/master by this push: new 8a2f4fb CAMEL-15460: FTP reconnect to handle pending command and noop result (#4125) 8a2f4fb is described below commit 8a2f4fb8ce9b318eb2f50b9d403f4e7d323672cf Author: Lukas Holthof <68239695+lholt...@users.noreply.github.com> AuthorDate: Tue Aug 25 13:39:27 2020 +0200 CAMEL-15460: FTP reconnect to handle pending command and noop result (#4125) --- .../camel/component/file/remote/FtpOperations.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 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 40e2e28..1d9741a 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 @@ -353,7 +353,6 @@ public class FtpOperations implements RemoteFileOperations<FTPFile> { public boolean renameFile(String from, String to) throws GenericFileOperationFailedException { log.debug("Renaming file: {} to: {}", from, to); try { - reconnectIfNecessary(null); return client.rename(from, to); } catch (IOException e) { throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e); @@ -1009,16 +1008,18 @@ public class FtpOperations implements RemoteFileOperations<FTPFile> { } private void reconnectIfNecessary(Exchange exchange) throws GenericFileOperationFailedException { - if (isConnected()) { - log.trace("sendNoOp to check if connection should be reconnected"); - try { - client.sendNoOp(); - } catch (IOException e) { - log.trace("NoOp to server failed, try to reconnect"); - connect(endpoint.getConfiguration(), exchange); + boolean reconnectRequired = false; + try { + client.completePendingCommand(); + if (!isConnected() || !sendNoop()) { + reconnectRequired = true; } - } else { - log.trace("Client is not connected, try to reconnect"); + } catch (IOException | GenericFileOperationFailedException e) { + // Ignore Exception and reconnect the client + reconnectRequired = true; + } + if (reconnectRequired) { + log.trace("Client is not connected anymore, try to reconnect"); connect(endpoint.getConfiguration(), exchange); } }