<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Close anSSH tunnel connection in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275238#M51672</link>
    <description>Are you using the component from exchange:&lt;BR /&gt;&lt;A href="https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%2F1&amp;amp;pi=marketplace%2F1%2Fproducts%2F678%2Fitems%2F987" target="_blank" rel="nofollow noopener noreferrer"&gt;https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%252F1&amp;amp;pi=marketplace%252F1%252Fproducts%252F678%252Fitems%252F987&lt;/A&gt;&lt;BR /&gt;Thomas</description>
    <pubDate>Tue, 15 Mar 2016 05:39:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-03-15T05:39:47Z</dc:date>
    <item>
      <title>Close anSSH tunnel connection</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275237#M51671</link>
      <description>Hi, 
&lt;BR /&gt;currently we work on the exchange component tSshTunnel to open a tunnel with a forwarding port (L string) to secure a non secure data base.(SSL solution is not possible). 
&lt;BR /&gt;It works fine one shot but the tunnel keep open during a few minutes (15-30) and I can't reopen the same ssh tunnel forwarding: I can't serialize job execution, and more not paralyze. 
&lt;BR /&gt;The tSshTunnel use the librairy Jsch. It creates a connection session. It applies&amp;nbsp; connect() to open the tunnel but don't close them at the end of component use with&amp;nbsp; disconnect(). 
&lt;BR /&gt;I'm not java developer but how can I use the disconnect() method to the session object creates in the component ? 
&lt;BR /&gt;Other method to close is to identify the process ID and kill them. 
&lt;BR /&gt;Regards 
&lt;BR /&gt;Jeremie 
&lt;BR /&gt; 
&lt;BR /&gt;--------------------------------------------------------------------- 
&lt;BR /&gt;JAVA code component bloc in the job 
&lt;BR /&gt; 
&lt;PRE&gt;public void tSshTunnel_1Process(&lt;BR /&gt;			final java.util.Map&amp;lt;String, Object&amp;gt; globalMap)&lt;BR /&gt;			throws TalendException {&lt;BR /&gt;		globalMap.put("tSshTunnel_1_SUBPROCESS_STATE", 0);&lt;BR /&gt;		final boolean execStat = this.execStat;&lt;BR /&gt;		String iterateId = "";&lt;BR /&gt;		String currentComponent = "";&lt;BR /&gt;		java.util.Map&amp;lt;String, Object&amp;gt; resourceMap = new java.util.HashMap&amp;lt;String, Object&amp;gt;();&lt;BR /&gt;		try {&lt;BR /&gt;			String currentMethodName = new java.lang.Exception()&lt;BR /&gt;					.getStackTrace().getMethodName();&lt;BR /&gt;			boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);&lt;BR /&gt;			if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start&lt;BR /&gt;																					// the&lt;BR /&gt;																					// resume&lt;BR /&gt;				globalResumeTicket = true;&lt;BR /&gt;				/**&lt;BR /&gt;				 *  start&lt;BR /&gt;				 */&lt;BR /&gt;				ok_Hash.put("tSshTunnel_1", false);&lt;BR /&gt;				start_Hash.put("tSshTunnel_1", System.currentTimeMillis());&lt;BR /&gt;				currentComponent = "tSshTunnel_1";&lt;BR /&gt;				int tos_count_tSshTunnel_1 = 0;&lt;BR /&gt;				java.util.Hashtable&amp;lt;String, com.jcraft.jsch.Session&amp;gt; tunnels_tSshTunnel_1 = new java.util.Hashtable&amp;lt;String, com.jcraft.jsch.Session&amp;gt;();&lt;BR /&gt;				boolean useKey_tSshTunnel_1_0 = false;&lt;BR /&gt;				if (!((String) globalMap.get("tCreateTemporaryFile_1_FILEPATH"))&lt;BR /&gt;						.equals(""))&lt;BR /&gt;					useKey_tSshTunnel_1_0 = true;&lt;BR /&gt;				if (!tunnels_tSshTunnel_1&lt;BR /&gt;						.containsKey(context.connection_sshtunnel_username&lt;BR /&gt;								+ "@" + context.connection_sshtunnel_hostname&lt;BR /&gt;								+ ":" + context.connection_sshtunnel_port)) {&lt;BR /&gt;					com.jcraft.jsch.JSch j = new com.jcraft.jsch.JSch();&lt;BR /&gt;					if (useKey_tSshTunnel_1_0)&lt;BR /&gt;						j.addIdentity(((String) globalMap&lt;BR /&gt;								.get("tCreateTemporaryFile_1_FILEPATH")));&lt;BR /&gt;					com.jcraft.jsch.Session session = j&lt;BR /&gt;							.getSession(&lt;BR /&gt;									context.connection_sshtunnel_username,&lt;BR /&gt;									context.connection_sshtunnel_hostname,&lt;BR /&gt;									Integer.parseInt(context.connection_sshtunnel_port));&lt;BR /&gt;					java.util.Hashtable&amp;lt;String, String&amp;gt; config = new java.util.Hashtable&amp;lt;String, String&amp;gt;();&lt;BR /&gt;					config.put("StrictHostKeyChecking", "no");&lt;BR /&gt;					session.setConfig(config);&lt;BR /&gt;					if (!useKey_tSshTunnel_1_0) {&lt;BR /&gt;						session.setPassword(context.connection_sshtunnel_password);&lt;BR /&gt;					}&lt;BR /&gt;					session.connect();&lt;BR /&gt;					String[] credentials = context.connection_sshtunnel_ltunnelstring&lt;BR /&gt;							.split(":");&lt;BR /&gt;					session.setPortForwardingL(&lt;BR /&gt;							Integer.parseInt(credentials), credentials,&lt;BR /&gt;							Integer.parseInt(credentials));&lt;BR /&gt;					tunnels_tSshTunnel_1.put(&lt;BR /&gt;							context.connection_sshtunnel_username + "@"&lt;BR /&gt;									+ context.connection_sshtunnel_hostname&lt;BR /&gt;									+ ":" + context.connection_sshtunnel_port,&lt;BR /&gt;							session);&lt;BR /&gt;				} else {&lt;BR /&gt;					com.jcraft.jsch.Session session = tunnels_tSshTunnel_1&lt;BR /&gt;							.get(context.connection_sshtunnel_username + "@"&lt;BR /&gt;									+ context.connection_sshtunnel_hostname&lt;BR /&gt;									+ ":" + context.connection_sshtunnel_port);&lt;BR /&gt;					String[] credentials = context.connection_sshtunnel_ltunnelstring&lt;BR /&gt;							.split(":");&lt;BR /&gt;					session.setPortForwardingL(&lt;BR /&gt;							Integer.parseInt(credentials), credentials,&lt;BR /&gt;							Integer.parseInt(credentials));&lt;BR /&gt;				}&lt;BR /&gt;				globalMap.put("tunnels_tSshTunnel_1", tunnels_tSshTunnel_1);&lt;BR /&gt;				/**&lt;BR /&gt;				 *  stop&lt;BR /&gt;				 */&lt;BR /&gt;				/**&lt;BR /&gt;				 *  start&lt;BR /&gt;				 */&lt;BR /&gt;				currentComponent = "tSshTunnel_1";&lt;BR /&gt;				tos_count_tSshTunnel_1++;&lt;BR /&gt;				/**&lt;BR /&gt;				 *  stop&lt;BR /&gt;				 */&lt;BR /&gt;				/**&lt;BR /&gt;				 *  start&lt;BR /&gt;				 */&lt;BR /&gt;				currentComponent = "tSshTunnel_1";&lt;BR /&gt;				ok_Hash.put("tSshTunnel_1", true);&lt;BR /&gt;				end_Hash.put("tSshTunnel_1", System.currentTimeMillis());&lt;BR /&gt;				tSystem_1Process(globalMap);&lt;BR /&gt;				/**&lt;BR /&gt;				 *  stop&lt;BR /&gt;				 */&lt;BR /&gt;			}// end the resume&lt;BR /&gt;		} catch (java.lang.Exception e) {&lt;BR /&gt;			if (!(e instanceof TalendException)) {&lt;BR /&gt;				log.fatal(currentComponent + " " + e.getMessage());&lt;BR /&gt;			}&lt;BR /&gt;			TalendException te = new TalendException(e, currentComponent,&lt;BR /&gt;					globalMap);&lt;BR /&gt;			throw te;&lt;BR /&gt;		} catch (java.lang.Error error) {&lt;BR /&gt;			throw error;&lt;BR /&gt;		} finally {&lt;BR /&gt;			try {&lt;BR /&gt;				/**&lt;BR /&gt;				 *  start&lt;BR /&gt;				 */&lt;BR /&gt;				currentComponent = "tSshTunnel_1";&lt;BR /&gt;				/**&lt;BR /&gt;				 *  stop&lt;BR /&gt;				 */&lt;BR /&gt;			} catch (java.lang.Exception e) {&lt;BR /&gt;				// ignore&lt;BR /&gt;			} catch (java.lang.Error error) {&lt;BR /&gt;				// ignore&lt;BR /&gt;			}&lt;BR /&gt;			resourceMap = null;&lt;BR /&gt;		}&lt;BR /&gt;		globalMap.put("tSshTunnel_1_SUBPROCESS_STATE", 1);&lt;BR /&gt;	}&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Nov 2024 10:44:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275237#M51671</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T10:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Close anSSH tunnel connection</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275238#M51672</link>
      <description>Are you using the component from exchange:&lt;BR /&gt;&lt;A href="https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%2F1&amp;amp;pi=marketplace%2F1%2Fproducts%2F678%2Fitems%2F987" target="_blank" rel="nofollow noopener noreferrer"&gt;https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%252F1&amp;amp;pi=marketplace%252F1%252Fproducts%252F678%252Fitems%252F987&lt;/A&gt;&lt;BR /&gt;Thomas</description>
      <pubDate>Tue, 15 Mar 2016 05:39:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275238#M51672</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-15T05:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Close anSSH tunnel connection</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275239#M51673</link>
      <description>Hi&amp;nbsp; 
&lt;FONT size="2"&gt;&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;Jeremie&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;I think you should close the session after the component, for example:&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;tSSHTunnel&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;&amp;nbsp; &amp;nbsp;|&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;&lt;FONT size="2"&gt;onsubjobok&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp; |&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;&lt;FONT size="2"&gt;do your business&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;&lt;FONT size="2"&gt;&amp;nbsp; |&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;&lt;FONT size="2"&gt;tJava&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt;on tJava, close the session. 
&lt;BR /&gt; 
&lt;PRE&gt;&lt;BR /&gt;com.jcraft.jsch.Session session=(com.jcraft.jsch.Session)globalMap.get("session");&lt;BR /&gt;session.disconnect();&lt;/PRE&gt; 
&lt;BR /&gt;In order to get the session on another component, &amp;nbsp;you need to modify the source file of component, open the&amp;nbsp;tSshTunnel_begin.javajet file and edit it as below: 
&lt;BR /&gt; 
&lt;PRE&gt;&amp;lt;%@ jet &lt;BR /&gt;imports="&lt;BR /&gt;    	org.talend.core.model.process.INode    &lt;BR /&gt;		org.talend.designer.codegen.config.CodeGeneratorArgument&lt;BR /&gt;		org.talend.core.model.process.ElementParameterParser &lt;BR /&gt;		java.util.List&lt;BR /&gt;		java.util.Map&lt;BR /&gt;		" &lt;BR /&gt;%&amp;gt;&lt;BR /&gt;&amp;lt;%&lt;BR /&gt;	CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;&lt;BR /&gt;	INode node = (INode)codeGenArgument.getArgument();&lt;BR /&gt;	String cid = node.getUniqueName();&lt;BR /&gt;	List&amp;lt;Map&amp;lt;String, String&amp;gt;&amp;gt; lines = (List&amp;lt;Map&amp;lt;String, String&amp;gt;&amp;gt;)ElementParameterParser.getObjectValue(node, "__TUNNELS__");&lt;BR /&gt;	&lt;BR /&gt;%&amp;gt; &lt;BR /&gt;    com.jcraft.jsch.Session session;&lt;BR /&gt;	java.util.Hashtable&amp;lt;String,com.jcraft.jsch.Session&amp;gt; tunnels_&amp;lt;%=cid %&amp;gt; = new java.util.Hashtable&amp;lt;String,com.jcraft.jsch.Session&amp;gt;();&lt;BR /&gt;&amp;lt;%&lt;BR /&gt;  for (int i=0; i&amp;lt;lines.size(); i++) {&lt;BR /&gt;    Map&amp;lt;String, String&amp;gt; line = lines.get(i);&lt;BR /&gt;    &lt;BR /&gt;%&amp;gt;&lt;BR /&gt;	boolean useKey_&amp;lt;%=cid %&amp;gt;_&amp;lt;%=i%&amp;gt;=false;&lt;BR /&gt;	if (!&amp;lt;%=line.get("KEYFILE")%&amp;gt;.equals(""))&lt;BR /&gt;		useKey_&amp;lt;%=cid %&amp;gt;_&amp;lt;%=i%&amp;gt;=true;&lt;BR /&gt;		&lt;BR /&gt;	if (!tunnels_&amp;lt;%=cid %&amp;gt;.containsKey(&amp;lt;%=line.get("USERNAME")%&amp;gt;+"@"+&amp;lt;%=line.get("HOST")%&amp;gt;+":"+&amp;lt;%=line.get("PORT")%&amp;gt;)) {&lt;BR /&gt;		com.jcraft.jsch.JSch j=new com.jcraft.jsch.JSch();&lt;BR /&gt;		if(useKey_&amp;lt;%=cid %&amp;gt;_&amp;lt;%=i%&amp;gt;)&lt;BR /&gt;			j.addIdentity(&amp;lt;%=line.get("KEYFILE")%&amp;gt;);&lt;BR /&gt;	   session=j.getSession(&amp;lt;%=line.get("USERNAME")%&amp;gt;,&amp;lt;%=line.get("HOST")%&amp;gt;,Integer.parseInt(&amp;lt;%=line.get("PORT")%&amp;gt;));&lt;BR /&gt;		java.util.Hashtable&amp;lt;String, String&amp;gt; config = new java.util.Hashtable&amp;lt;String, String&amp;gt;();&lt;BR /&gt;		config.put("StrictHostKeyChecking", "no");&lt;BR /&gt;		session.setConfig(config);&lt;BR /&gt;		if (!useKey_&amp;lt;%=cid %&amp;gt;_&amp;lt;%=i%&amp;gt;) {&lt;BR /&gt;			session.setPassword(&amp;lt;%=line.get("PASSWORD")%&amp;gt;);&lt;BR /&gt;		}&lt;BR /&gt;		session.connect();&lt;BR /&gt;		String[] credentials = &amp;lt;%=line.get("L_TUNNEL_STRING")%&amp;gt;.split(":");&lt;BR /&gt;		session.setPortForwardingL(Integer.parseInt(credentials), credentials, Integer.parseInt(credentials));&lt;BR /&gt;		tunnels_&amp;lt;%=cid %&amp;gt;.put(&amp;lt;%=line.get("USERNAME")%&amp;gt;+"@"+&amp;lt;%=line.get("HOST")%&amp;gt;+":"+&amp;lt;%=line.get("PORT")%&amp;gt;,session);&lt;BR /&gt;		&lt;BR /&gt;	} else {&lt;BR /&gt;	    session = tunnels_&amp;lt;%=cid %&amp;gt;.get(&amp;lt;%=line.get("USERNAME")%&amp;gt;+"@"+&amp;lt;%=line.get("HOST")%&amp;gt;+":"+&amp;lt;%=line.get("PORT")%&amp;gt;);&lt;BR /&gt;		String[] credentials = &amp;lt;%=line.get("L_TUNNEL_STRING")%&amp;gt;.split(":");&lt;BR /&gt;		session.setPortForwardingL(Integer.parseInt(credentials), credentials, Integer.parseInt(credentials));&lt;BR /&gt;	}&lt;BR /&gt;	globalMap.put("session",session);&lt;BR /&gt;	globalMap.put("tunnels_&amp;lt;%=cid %&amp;gt;",tunnels_&amp;lt;%=cid %&amp;gt;);&lt;BR /&gt;&amp;lt;%&lt;BR /&gt;  }&lt;BR /&gt;%&amp;gt;&lt;BR /&gt;&lt;/PRE&gt; 
&lt;BR /&gt;Regards 
&lt;BR /&gt;Shong</description>
      <pubDate>Tue, 15 Mar 2016 08:40:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275239#M51673</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-15T08:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Close anSSH tunnel connection</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275240#M51674</link>
      <description>Hi,&lt;BR /&gt; I use the component on Talend Exchange&lt;BR /&gt;thanks for all information and code, I have test them with succeed.&lt;BR /&gt;I think I can include the java code in the&amp;nbsp; tSshTunnel_end.javajet ?&lt;BR /&gt;Best regards&lt;BR /&gt;Jeremie</description>
      <pubDate>Tue, 15 Mar 2016 13:43:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275240#M51674</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-15T13:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Close anSSH tunnel connection</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275241#M51675</link>
      <description>Hi&amp;nbsp;&lt;BR /&gt;The session should be closed after your business processing, so you can create a new component such as tSSHClose to close the session, such as tMysqlClose.&amp;nbsp;</description>
      <pubDate>Tue, 15 Mar 2016 14:35:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275241#M51675</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-15T14:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Close anSSH tunnel connection</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275242#M51676</link>
      <description>Thanks&lt;BR /&gt;Jeremie</description>
      <pubDate>Tue, 15 Mar 2016 17:49:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Close-anSSH-tunnel-connection/m-p/2275242#M51676</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-15T17:49:32Z</dc:date>
    </item>
  </channel>
</rss>

