obligatory ssh client close()
This commit is contained in:
parent
0d0fbe167b
commit
a1cd358787
7 changed files with 15 additions and 11 deletions
|
@ -37,6 +37,7 @@ public class SFTPContext implements Closeable {
|
|||
@Override
|
||||
public void close() throws IOException {
|
||||
sshClient.stop();
|
||||
sshClient.close();
|
||||
fileSystem.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -472,8 +472,4 @@ public class SFTPFileService implements FileService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T performWithoutClose(SFTPContext ctx, WithContext<T> action) throws IOException {
|
||||
return action.perform(ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
package org.apache.sshd.fs.test;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.files.FileService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class FileServiceProviderTest {
|
||||
|
||||
@Test
|
||||
public void testSFTP() throws IOException {
|
||||
public void testSFTP() throws Exception {
|
||||
Map<String, ?> env = Map.of("username", "joerg");
|
||||
FileService fs = FileService.newInstance("sftp://alkmene:22", env);
|
||||
fs.list(".").forEach(p -> Logger.getAnonymousLogger().info(p.toString()));
|
||||
// close() is essential!
|
||||
try (Stream<Path> list = fs.list(".")) {
|
||||
list.forEach(p -> Logger.getAnonymousLogger().info(p.toString()));
|
||||
}
|
||||
// see if a second run still works
|
||||
try (Stream<Path> list = fs.list(".")) {
|
||||
list.forEach(p -> Logger.getAnonymousLogger().info(p.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,5 +37,6 @@ public class SFTPFileSystemTest {
|
|||
fileSystem.close();
|
||||
// ...
|
||||
sshClient.stop();
|
||||
sshClient.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -652,7 +652,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
|
|||
protected SshFutureListener<IoConnectFuture> createConnectCompletionListener(
|
||||
ConnectFuture connectFuture, String username, SocketAddress address,
|
||||
KeyIdentityProvider identities, boolean useDefaultIdentities) {
|
||||
return new SshFutureListener<IoConnectFuture>() {
|
||||
return new SshFutureListener<>() {
|
||||
@Override
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public void operationComplete(IoConnectFuture future) {
|
||||
|
@ -660,7 +660,6 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
|
|||
connectFuture.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
Throwable t = future.getException();
|
||||
if (t != null) {
|
||||
connectFuture.setException(t);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.sshd.common;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.channels.Channel;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.apache.sshd.common.future.CloseFuture;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
group = org.xbib
|
||||
name = files
|
||||
version = 4.4.0
|
||||
version = 4.5.0
|
||||
|
|
Loading…
Reference in a new issue