Example usage for org.springframework.integration.sftp.session JSchSessionWrapper addChannel

List of usage examples for org.springframework.integration.sftp.session JSchSessionWrapper addChannel

Introduction

In this page you can find the example usage for org.springframework.integration.sftp.session JSchSessionWrapper addChannel.

Prototype

public void addChannel() 

Source Link

Usage

From source file:org.springframework.integration.sftp.session.DefaultSftpSessionFactory.java

@Override
public SftpSession getSession() {
    Assert.hasText(this.host, "host must not be empty");
    Assert.hasText(this.user, "user must not be empty");
    Assert.isTrue(StringUtils.hasText(this.userInfoWrapper.getPassword()) || this.privateKey != null,
            "either a password or a private key is required");
    try {//from   w  ww . ja  va 2s . co m
        JSchSessionWrapper jschSession;
        if (this.isSharedSession) {
            this.sharedSessionLock.readLock().lock();
            try {
                if (this.sharedJschSession == null || !this.sharedJschSession.isConnected()) {
                    this.sharedSessionLock.readLock().unlock();
                    this.sharedSessionLock.writeLock().lock();
                    try {
                        if (this.sharedJschSession == null || !this.sharedJschSession.isConnected()) {
                            this.sharedJschSession = new JSchSessionWrapper(initJschSession());
                            try {
                                this.sharedJschSession.getSession().connect();
                            } catch (JSchException e) {
                                throw new IllegalStateException("failed to connect", e);
                            }
                        }
                    } finally {
                        this.sharedSessionLock.readLock().lock();
                        this.sharedSessionLock.writeLock().unlock();
                    }
                }
            } finally {
                this.sharedSessionLock.readLock().unlock();
            }
            jschSession = this.sharedJschSession;
        } else {
            jschSession = new JSchSessionWrapper(initJschSession());
        }
        SftpSession sftpSession = new SftpSession(jschSession);
        sftpSession.connect();
        jschSession.addChannel();
        return sftpSession;
    } catch (Exception e) {
        throw new IllegalStateException("failed to create SFTP Session", e);
    }
}