Migrated from Spring Integration 5.5 to 6.2.3 and cannot configure Keep Alive for sftp

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?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật