GH-171 Fix SFTP Supplier
Related to: https://github.com/spring-cloud/stream-applications/issues/171 It might not be necessary in real world, but with `SshServer` we fail when we disconnect the session and cannot connect it back because that server decides to die for a strange reason like no connections. * Upgrade to SSHD 2.7.0 * Wrap default SFTP SF into a `CachingSessionFactory` to keep sessions opened and don't let the server to die because on connections from clients * Reenable SFTP Supplier tests
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<description>file consumer</description>
|
||||
|
||||
<properties>
|
||||
<sshd-core.version>1.6.0</sshd-core.version>
|
||||
<sshd-sftp.version>2.7.0</sshd-sftp.version>
|
||||
<apache-ftpserver.version>1.1.1</apache-ftpserver.version>
|
||||
<awaitility.version>4.0.3</awaitility.version>
|
||||
</properties>
|
||||
@@ -47,8 +47,8 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.sshd</groupId>
|
||||
<artifactId>sshd-core</artifactId>
|
||||
<version>${sshd-core.version}</version>
|
||||
<artifactId>sshd-sftp</artifactId>
|
||||
<version>${sshd-sftp.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.Collections;
|
||||
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
|
||||
import org.apache.sshd.server.SshServer;
|
||||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
||||
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
|
||||
import org.apache.sshd.sftp.server.SftpSubsystemFactory;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class SftpTestSupport extends RemoteFileTestSupport {
|
||||
StringUtils.hasText(password) && !"badPassword".equals(password)); // fail if pub key validation failed
|
||||
server.setPublickeyAuthenticator((username, key, session) -> key.equals(decodePublicKey("id_rsa_pp.pub")));
|
||||
server.setPort(0);
|
||||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser")));
|
||||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
|
||||
server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
|
||||
server.setFileSystemFactory(new VirtualFileSystemFactory(remoteTemporaryFolder));
|
||||
server.start();
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.file.remote.aop.StandardRotationPolicy;
|
||||
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
||||
import org.springframework.integration.file.remote.session.DelegatingSessionFactory;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
|
||||
@@ -87,7 +88,7 @@ public class SftpSupplierFactoryConfiguration {
|
||||
sftpSessionFactory.setKnownHostsResource(new FileSystemResource(path));
|
||||
}
|
||||
|
||||
return sftpSessionFactory;
|
||||
return new CachingSessionFactory<>(sftpSessionFactory);
|
||||
}
|
||||
|
||||
public final static class DelegatingFactoryWrapper implements DisposableBean {
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -220,7 +219,6 @@ public class SftpSupplierApplicationTests extends SftpTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void deleteRemoteFiles() {
|
||||
defaultApplicationContextRunner
|
||||
.withPropertyValues(
|
||||
@@ -241,7 +239,6 @@ public class SftpSupplierApplicationTests extends SftpTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void renameRemoteFilesStream() {
|
||||
defaultApplicationContextRunner
|
||||
.withPropertyValues(
|
||||
@@ -252,7 +249,6 @@ public class SftpSupplierApplicationTests extends SftpTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void renameRemoteFiles() {
|
||||
defaultApplicationContextRunner
|
||||
.withPropertyValues(
|
||||
|
||||
Reference in New Issue
Block a user