GH-3123: Don't logout FtpSession if not connected

Fixes https://github.com/spring-projects/spring-integration/issues/3123
This commit is contained in:
div
2019-12-17 16:43:43 +10:00
committed by Artem Bilan
parent 1334c75147
commit c6358a93d4
2 changed files with 5 additions and 2 deletions

View File

@@ -38,6 +38,7 @@ import org.springframework.util.ObjectUtils;
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
* @author Den Ivanov
*
* @since 2.0
*/
@@ -154,7 +155,9 @@ public class FtpSession implements Session<FTPFile> {
if (this.readingRaw.get() && !finalizeRaw() && LOGGER.isWarnEnabled()) {
LOGGER.warn("Finalize on readRaw() returned false for " + this);
}
this.client.logout();
if (this.client.isConnected()) {
this.client.logout();
}
this.client.disconnect();
}
catch (Exception e) {

View File

@@ -69,6 +69,7 @@ class SessionFactoryTests {
sessionFactory.setDataTimeout(789);
doReturn(200).when(client).getReplyCode();
doReturn(true).when(client).login("foo", null);
doReturn(true).when(client).isConnected();
FtpSession session = sessionFactory.getSession();
verify(client).setConnectTimeout(123);
verify(client).setDefaultTimeout(456);
@@ -210,7 +211,6 @@ class SessionFactoryTests {
session.close();
}
catch (Exception e) {
e.printStackTrace();
failures.incrementAndGet();
}
});