After upgrade to Spring Integration 6.2.3 from 5.5 the DefaultSftpSessionFactory
seems to lose keep alive config methods:
defaultSftpSessionFactory.setServerAliveInterval(keepAliveInterval);
defaultSftpSessionFactory.setServerAliveCountMax(keepAliveCountMax);
With the new version there’s a change from using com.jcraft.jsch
to org.apache.sshd.sftp
which is responsible for SftpClient
configuration
But I struggle to find proper methods to set the properties
What else the new upgrade brought is a warning message about keep alive that I found some suggestions in another SO topic: /a/76907200/1873995 however they don’t work. It relates to https://issues.apache.org/jira/browse/SSHD-1237 but the code was merged to master with no release yet
Warning message:
2024-05-14T10:09:46.686+02:00 WARN 29596 --- [-nio2-thread-12] i.DefaultSftpClient$SftpChannelSubsystem : handleUnknownChannelRequest(SftpChannelSubsystem[id=0, recipient=0]-ClientSessionImpl[[email protected]/123.123.123.22:22][sftp]) Unknown channel request: [email protected][want-reply=true]
I have no clue from where the message is being started and why there’s this address specified: [email protected]
as I don’t have it hardcoded anywhere
The suggested code to create custom SshClient
and also a suggestion to use a custom DefaultSftpSessionFactory
with a handler that’s gonna handled Unknown channel requests but the following code also fails to reach that goal
@Bean
public SessionFactory<SftpClient.DirEntry> sftpSessionFactory() {
SshClient client = customSshClient();
DefaultSftpSessionFactory factory = new CustomSftpSessionFactory(client, reuseSession);
factory.setHost(host);
factory.setPort(port);
factory.setUser(username);
// if (keepAliveInterval > 0) { // TODO
// factory.setServerAliveInterval(keepAliveInterval);
// factory.setServerAliveCountMax(keepAliveCountMax);
// }
return new CachingSessionFactory<>(factory);
}
private SshClient customSshClient() {
final SshClient client = SshClient.setUpDefaultClient();
List<RequestHandler<ConnectionService>> oldHandlers = client.getGlobalRequestHandlers();
List<RequestHandler<ConnectionService>> handlers = new ArrayList<>();
if (GenericUtils.isNotEmpty(oldHandlers)) {
handlers.addAll(oldHandlers);
}
handlers.add(KeepAliveHandler.INSTANCE);
client.setGlobalRequestHandlers(handlers);
client.addPasswordIdentity(password);
client.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE);
return client;
}
public class CustomSftpSessionFactory extends DefaultSftpSessionFactory {
public CustomSftpSessionFactory(final SshClient sshClient, final boolean isSharedSession) {
super(sshClient, isSharedSession);
}
@Override
protected SftpClient createSftpClient(ClientSession clientSession, SftpVersionSelector initialVersionSelector, SftpErrorDataHandler errorDataHandler) throws IOException {
SftpClient client = super.createSftpClient(clientSession, initialVersionSelector, errorDataHandler);
client.getSession().setUnknownChannelReferenceHandler(new CustomUnknownChannelReferenceHandler());
// client.getClientSession().setUnknownChannelReferenceHandler(new CustomUnknownChannelReferenceHandler());
return client;
}
protected class CustomUnknownChannelReferenceHandler implements UnknownChannelReferenceHandler {
@Override
public Channel handleUnknownChannelCommand(ConnectionService service, byte cmd, long channelId, Buffer buffer) throws IOException {
return null;
}
}
}
The question is: how to get rid of the warning message and how to setup the keep alive settings?