View | Details | Raw Unified | Return to bug 187301 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java (-10 / +60 lines)
Lines 18-23 Link Here
18
package org.eclipse.rse.internal.connectorservice.telnet;
18
package org.eclipse.rse.internal.connectorservice.telnet;
19
19
20
import java.io.InputStream;
20
import java.io.InputStream;
21
import java.io.OutputStream;
21
import java.io.PrintStream;
22
import java.io.PrintStream;
22
import java.lang.reflect.InvocationTargetException;
23
import java.lang.reflect.InvocationTargetException;
23
24
Lines 60-66 Link Here
60
61
61
	private static final int TELNET_DEFAULT_PORT = 23; // TODO Make configurable
62
	private static final int TELNET_DEFAULT_PORT = 23; // TODO Make configurable
62
	private static final int TELNET_CONNECT_TIMEOUT = 60; //seconds - TODO: Make configurable
63
	private static final int TELNET_CONNECT_TIMEOUT = 60; //seconds - TODO: Make configurable
63
	private TelnetClient fTelnetClient = new TelnetClient();
64
	private TelnetClient fTelnetClient ;
64
	private SessionLostHandler fSessionLostHandler;
65
	private SessionLostHandler fSessionLostHandler;
65
	private InputStream in;
66
	private InputStream in;
66
	private PrintStream out;
67
	private PrintStream out;
Lines 69-75 Link Here
69
	private static final int SUCCESS_CODE = 150; // login pass code
70
	private static final int SUCCESS_CODE = 150; // login pass code
70
	private static final int CONNECT_CLOSED = 200; // code for end of login attempts
71
	private static final int CONNECT_CLOSED = 200; // code for end of login attempts
71
	private static final int CONNECT_CANCELED = 250; // code for cancel progress
72
	private static final int CONNECT_CANCELED = 250; // code for cancel progress
72
73
	private int numberOfConnections = 0;
74
	private String sessionPassword = "";
75
	
73
	public TelnetConnectorService(IHost host) {
76
	public TelnetConnectorService(IHost host) {
74
		super(TelnetConnectorResources.TelnetConnectorService_Name,
77
		super(TelnetConnectorResources.TelnetConnectorService_Name,
75
				TelnetConnectorResources.TelnetConnectorService_Description,
78
				TelnetConnectorResources.TelnetConnectorService_Description,
Lines 116-125 Link Here
116
		Exception nestedException = null;
119
		Exception nestedException = null;
117
		try {
120
		try {
118
			Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
121
			Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
122
			fTelnetClient = new TelnetClient();
119
			fTelnetClient.connect(host, TELNET_DEFAULT_PORT);
123
			fTelnetClient.connect(host, TELNET_DEFAULT_PORT);
120
			SystemSignonInformation ssi = getSignonInformation();
124
			if( numberOfConnections == 0) {
121
			if (ssi != null) {
125
				SystemSignonInformation ssi = getSignonInformation();
122
				password = ssi.getPassword();
126
				if (ssi != null) {
127
					password = ssi.getPassword();
128
					setSessionPassword( password );
129
				}
130
			}else {
131
				password = getSessionPassword();
123
			}
132
			}
124
133
125
			in = fTelnetClient.getInputStream();
134
			in = fTelnetClient.getInputStream();
Lines 158-166 Link Here
158
				Activator.trace("Telnet Service: Canceled"); //$NON-NLS-1$
167
				Activator.trace("Telnet Service: Canceled"); //$NON-NLS-1$
159
				sessionDisconnect(); //will eventually destroy the LoginThread
168
				sessionDisconnect(); //will eventually destroy the LoginThread
160
			} else if (status == SUCCESS_CODE) {
169
			} else if (status == SUCCESS_CODE) {
161
				fSessionLostHandler = new SessionLostHandler(this);
170
				if( numberOfConnections == 0 ) {
162
				notifyConnection();
171
					fSessionLostHandler = new SessionLostHandler(this);
163
				Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
172
					notifyConnection();
173
					Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
174
				}
164
			} else {
175
			} else {
165
				Activator.trace("Telnet Service: Connect failed"); //$NON-NLS-1$
176
				Activator.trace("Telnet Service: Connect failed"); //$NON-NLS-1$
166
				//TODO pass the nested exception as well as original prompts
177
				//TODO pass the nested exception as well as original prompts
Lines 188-195 Link Here
188
		try {
199
		try {
189
			if (fTelnetClient != null) {
200
			if (fTelnetClient != null) {
190
				synchronized (fTelnetClient) {
201
				synchronized (fTelnetClient) {
191
					if (fTelnetClient.isConnected())
202
					if( numberOfConnections == 1) {
192
						fTelnetClient.disconnect();
203
						if (fTelnetClient.isConnected())
204
							fTelnetClient.disconnect();
205
					}else  {
206
						removeConnection();
207
					}
193
				}
208
				}
194
			}
209
			}
195
		} catch (Exception e) {
210
		} catch (Exception e) {
Lines 267-276 Link Here
267
		notifyDisconnection();
282
		notifyDisconnection();
268
	}
283
	}
269
284
285
	public InputStream getSessionInputStream() {
286
		return this.in;
287
	}
288
	
289
	public OutputStream getSessionOutputStream() {
290
		return this.out;
291
	}
292
	public void setSessionPassword( String passwd ) {
293
		this.sessionPassword = passwd;
294
	}
295
	
296
	public String getSessionPassword() {
297
		return this.sessionPassword;
298
	}
299
	
270
	public TelnetClient getTelnetClient() {
300
	public TelnetClient getTelnetClient() {
271
		return fTelnetClient;
301
		return fTelnetClient;
272
	}
302
	}
273
303
304
	public void addConnection() {
305
		numberOfConnections++;
306
	}
307
	
308
	public void removeConnection() {
309
		numberOfConnections--;
310
	}
311
	
312
	public int getNumberOfConnections() {
313
		return numberOfConnections;
314
		
315
	}
316
	
317
	public void createNewConnection() {
318
		try {
319
			internalConnect( null );
320
		} catch (Exception e) {
321
			SystemBasePlugin.logError(e.getMessage() == null ? 	e.getClass().getName() : e.getMessage(), e);
322
		}
323
	}
274
	/**
324
	/**
275
	 * Handle session-lost events. This is generic for any sort of connector
325
	 * Handle session-lost events. This is generic for any sort of connector
276
	 * service. Most of this is extracted from dstore's
326
	 * service. Most of this is extracted from dstore's
(-)src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java (-5 / +11 lines)
Lines 44-53 Link Here
44
		try {
44
		try {
45
			fSessionProvider = sessionProvider;
45
			fSessionProvider = sessionProvider;
46
			
46
			
47
47
			if( fSessionProvider.getNumberOfConnections() > 0) {
48
			fStdoutHandler = new TelnetShellOutputReader(this, new BufferedReader(new InputStreamReader(sessionProvider.getTelnetClient().getInputStream())), false);
48
				fSessionProvider.createNewConnection();
49
			}
50
			fSessionProvider.addConnection();
51
			fStdoutHandler = new TelnetShellOutputReader(this, new BufferedReader(new InputStreamReader(sessionProvider.getSessionInputStream())), false);
49
			fStderrHandler = new TelnetShellOutputReader(this, null,true);
52
			fStderrHandler = new TelnetShellOutputReader(this, null,true);
50
			OutputStream outputStream = sessionProvider.getTelnetClient().getOutputStream();
53
			OutputStream outputStream = sessionProvider.getSessionOutputStream();
51
			//TODO check if encoding or command to execute needs to be considered
54
			//TODO check if encoding or command to execute needs to be considered
52
			//If a command is given, it might be possible to do without a Thread
55
			//If a command is given, it might be possible to do without a Thread
53
			//Charset cs = Charset.forName(encoding);
56
			//Charset cs = Charset.forName(encoding);
Lines 88-97 Link Here
88
			TelnetClient client = fSessionProvider.getTelnetClient();
91
			TelnetClient client = fSessionProvider.getTelnetClient();
89
			if (client!=null) {
92
			if (client!=null) {
90
				synchronized(client) {
93
				synchronized(client) {
91
					if (client.isConnected())
94
					if( fSessionProvider.getNumberOfConnections() <= 1 ) {
92
						client.disconnect();
95
						if (client.isConnected())
96
							client.disconnect();
97
					}
93
				}
98
				}
94
			}
99
			}
100
			fSessionProvider.removeConnection();
95
		} catch (IOException e) {
101
		} catch (IOException e) {
96
		}
102
		}
97
103
(-)src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java (+20 lines)
Lines 16-27 Link Here
16
 *******************************************************************************/
16
 *******************************************************************************/
17
package org.eclipse.rse.internal.services.telnet;
17
package org.eclipse.rse.internal.services.telnet;
18
18
19
import java.io.InputStream;
20
import java.io.OutputStream;
21
19
import org.apache.commons.net.telnet.TelnetClient;
22
import org.apache.commons.net.telnet.TelnetClient;
20
23
21
public interface ITelnetSessionProvider {
24
public interface ITelnetSessionProvider {
22
	
25
	
26
	
23
	public TelnetClient getTelnetClient();
27
	public TelnetClient getTelnetClient();
24
	
28
	
25
	/* Inform the connectorService that a session has been lost. */
29
	/* Inform the connectorService that a session has been lost. */
26
	public void handleSessionLost();
30
	public void handleSessionLost();
31
	
32
	public void addConnection();
33
	
34
	public void removeConnection();
35
	
36
	public int getNumberOfConnections();
37
	
38
	public void createNewConnection();
39
	
40
	public void setSessionPassword( String passwd ) ;
41
	
42
	public String getSessionPassword();
43
	
44
	public InputStream getSessionInputStream();
45
	
46
	public OutputStream getSessionOutputStream();
27
}
47
}

Return to bug 187301