web stats
destroy() method from SftpConnection apparently doesn't work - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2011, 04:21 AM
carles carles is offline
OBX.2 Kenobi
 
Join Date: Mar 2007
Location: Girona
Posts: 62
carles is an unknown quantity at this point
Default destroy() method from SftpConnection apparently doesn't work

I've made a class similar to FileUtil (com.mirth.connect.server.util) in order to be able to connect to a sftp server. FileUtil only allows open files in the local filesystem.

This is the code

Code:
package cat.trueta;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.mirth.connect.connectors.file.filesystems.SftpConnection;

public class GironaSftpReader {
	
	public static String read(String host, int port, String username, String password, int timeout, String fileName, String path, Boolean delete) throws Exception {
		
		SftpConnection conn = new SftpConnection(host, port, username, password, timeout);
		InputStream inputStream = conn.readFile(fileName,path);
		BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
		StringBuilder contents = new StringBuilder();
		String line = null;

		try {
			while ((line = reader.readLine()) != null) {
				contents.append(line + "\n");
			}
		} finally {
			reader.close();
		}

                // delete after read
		if (delete) {
			conn.delete(fileName,path,true);
		}

                // disconnect sftp session
		
		conn.destroy();
		

                // return file contents
		return contents.toString();
	}
}
This class works well reading a file from a sftp server in a javascript connector, doing something like this:

Code:
var resultat = Packages.cat.trueta.GironaSftpReader.read(host,port,user,password, timeout,filename,path,deleteafterread);
return resultat;
After reading the file I call destroy method to quit the sftp connection, but it keeps always alive
After many executions of the channel, the sftp server reach the limit number of connections and refuse new ones.

What I did wrong?


Carles Massallé
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 06:05 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation