INT-1614 removed connect() from Session, renamed disconnect() to close()
This commit is contained in:
@@ -82,15 +82,15 @@ public class CachingSessionFactory implements SessionFactory, DisposableBean {
|
||||
public void destroy() {
|
||||
if (this.queue != null) {
|
||||
for (Session session : this.queue) {
|
||||
this.destroySession(session);
|
||||
this.closeSession(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void destroySession(Session session) {
|
||||
private void closeSession(Session session) {
|
||||
try {
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
@@ -108,16 +108,12 @@ public class CachingSessionFactory implements SessionFactory, DisposableBean {
|
||||
this.targetSession = targetSession;
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
targetSession.connect();
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
public void close() {
|
||||
if (queue.size() < maxPoolSize) {
|
||||
queue.add(targetSession);
|
||||
}
|
||||
else {
|
||||
targetSession.disconnect();
|
||||
targetSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,6 @@ import java.util.Collection;
|
||||
*/
|
||||
public interface Session {
|
||||
|
||||
void connect();
|
||||
|
||||
void disconnect();
|
||||
|
||||
boolean rm(String path);
|
||||
|
||||
<F> Collection<F> ls(String path);
|
||||
@@ -41,4 +37,6 @@ public interface Session {
|
||||
|
||||
void put(InputStream inputStream, String destination);
|
||||
|
||||
void close();
|
||||
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class FtpInboundFileSynchronizer extends AbstractInboundFileSynchronizer<
|
||||
}
|
||||
}
|
||||
finally {
|
||||
session.disconnect();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
@@ -186,7 +186,7 @@ public class FtpSendingMessageHandler extends AbstractMessageHandler{
|
||||
}
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
if (!sentSuccesfully) {
|
||||
|
||||
@@ -49,24 +49,6 @@ public class FtpSession implements Session {
|
||||
}
|
||||
|
||||
|
||||
public void connect() {
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
try {
|
||||
this.client.disconnect();
|
||||
}
|
||||
catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("failed to disconnect FTPClient", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean exists(String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean rm(String path) {
|
||||
try {
|
||||
this.client.deleteFile(path);
|
||||
@@ -137,4 +119,15 @@ public class FtpSession implements Session {
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.client.disconnect();
|
||||
}
|
||||
catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("failed to disconnect FTPClient", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ public class SftpInboundFileSynchronizer extends AbstractInboundFileSynchronizer
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Pooled SftpSession " + session + " from the pool");
|
||||
}
|
||||
session.connect();
|
||||
Collection<ChannelSftp.LsEntry> beforeFilter = session.ls(remotePath);
|
||||
ChannelSftp.LsEntry[] entries = (beforeFilter == null) ? new ChannelSftp.LsEntry[0] :
|
||||
beforeFilter.toArray(new ChannelSftp.LsEntry[beforeFilter.size()]);
|
||||
@@ -92,7 +91,7 @@ public class SftpInboundFileSynchronizer extends AbstractInboundFileSynchronizer
|
||||
throw new MessagingException("couldn't synchronize remote to local directory", e);
|
||||
}
|
||||
finally {
|
||||
session.disconnect();
|
||||
session.close();
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Putting SftpSession " + session + " back into the pool");
|
||||
}
|
||||
|
||||
@@ -169,7 +169,6 @@ public class SftpSendingMessageHandler extends AbstractMessageHandler {
|
||||
}
|
||||
InputStream fileInputStream = null;
|
||||
try {
|
||||
session.connect();
|
||||
fileInputStream = new FileInputStream(file);
|
||||
String baseOfRemotePath = "";
|
||||
if (this.directoryExpressionProcesor != null) {
|
||||
@@ -186,7 +185,7 @@ public class SftpSendingMessageHandler extends AbstractMessageHandler {
|
||||
}
|
||||
finally {
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
session.disconnect();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.integration.file.remote.session.Session;
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.SftpATTRS;
|
||||
import com.jcraft.jsch.SftpException;
|
||||
import com.jcraft.jsch.UserInfo;
|
||||
|
||||
@@ -109,26 +108,19 @@ public class DefaultSftpSession implements Session {
|
||||
}
|
||||
this.userInfo = new OptimisticUserInfoImpl(userPassword);
|
||||
this.jschSession.setUserInfo(userInfo);
|
||||
this.jschSession.connect();
|
||||
this.channel = (ChannelSftp) this.jschSession.openChannel("sftp");
|
||||
}
|
||||
|
||||
public ChannelSftp getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (!channel.isConnected()) {
|
||||
try {
|
||||
channel.connect();
|
||||
}
|
||||
catch (JSchException e) {
|
||||
throw new IllegalStateException("failed to connect", e);
|
||||
}
|
||||
void connect() {
|
||||
try {
|
||||
this.jschSession.connect();
|
||||
}
|
||||
catch (JSchException e) {
|
||||
throw new IllegalStateException("failed to connect", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
public void close() {
|
||||
if (jschSession.isConnected()) {
|
||||
jschSession.disconnect();
|
||||
if (channel.isConnected()) {
|
||||
@@ -137,19 +129,6 @@ public class DefaultSftpSession implements Session {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean exists(String path) {
|
||||
try {
|
||||
SftpATTRS attrs = channel.stat(path);
|
||||
return (attrs != null) && attrs.isDir();
|
||||
}
|
||||
catch (SftpException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("directoryExists failed", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mkdir(String path) {
|
||||
try {
|
||||
channel.mkdir(path);
|
||||
|
||||
@@ -86,7 +86,10 @@ public class SimpleSftpSessionFactory implements SessionFactory {
|
||||
if (privateKey != null){
|
||||
privateKeyToPass = privateKey.getFile().getAbsolutePath();
|
||||
}
|
||||
return new DefaultSftpSession(this.user, this.host, this.password, this.port, this.knownHosts, null, privateKeyToPass, this.privateKeyPassphrase);
|
||||
DefaultSftpSession session = new DefaultSftpSession(
|
||||
this.user, this.host, this.password, this.port, this.knownHosts, null, privateKeyToPass, this.privateKeyPassphrase);
|
||||
session.connect();
|
||||
return session;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("failed to create SFTP Session", e);
|
||||
|
||||
Reference in New Issue
Block a user