GH-3090: Add logout() to FtpSession.close()`

Fixes https://github.com/spring-projects/spring-integration/issues/3090

Without `logout()` the FTP session is not closed at all,
but just the connection is closed.
Some FTP servers close those sessions eventually anyway, but some just
leak with resources.

**Cherry-pick to 5.1.x & 4.3.x**
This commit is contained in:
Artem Bilan
2019-10-30 14:44:50 -04:00
committed by Gary Russell
parent 35b964cc79
commit 315fafdaf2
2 changed files with 9 additions and 3 deletions

View File

@@ -153,6 +153,7 @@ public class FtpSession implements Session<FTPFile> {
}
}
}
this.client.logout();
this.client.disconnect();
}
catch (Exception e) {
@@ -196,7 +197,6 @@ public class FtpSession implements Session<FTPFile> {
return this.client.removeDirectory(directory);
}
@Override
public boolean exists(String path) throws IOException {
Assert.hasText(path, "'path' must not be empty");

View File

@@ -45,6 +45,7 @@ import org.springframework.integration.util.PoolItemNotAvailableException;
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -52,7 +53,7 @@ public class SessionFactoryTests {
@Test
public void testTimeouts() throws Exception {
public void testFtpClientInteraction() throws Exception {
final FTPClient client = mock(FTPClient.class);
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory() {
@@ -67,10 +68,15 @@ public class SessionFactoryTests {
sessionFactory.setDataTimeout(789);
doReturn(200).when(client).getReplyCode();
doReturn(true).when(client).login("foo", null);
sessionFactory.getSession();
FtpSession session = sessionFactory.getSession();
verify(client).setConnectTimeout(123);
verify(client).setDefaultTimeout(456);
verify(client).setDataTimeout(789);
session.close();
verify(client).logout();
verify(client).disconnect();
}
@Test