Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 187301 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java (-3 / +9 lines)
Lines 13-27 Link Here
13
 * 
13
 * 
14
 * Contributors:
14
 * Contributors:
15
 * Sheldon D'souza (Celunite) - adapted from ISshSessionProvider
15
 * Sheldon D'souza (Celunite) - adapted from ISshSessionProvider
16
 * Sheldon D'souza (Celunite) - [187301] support multiple telnet shells
16
 *******************************************************************************/
17
 *******************************************************************************/
17
package org.eclipse.rse.internal.services.telnet;
18
package org.eclipse.rse.internal.services.telnet;
18
19
19
import org.apache.commons.net.telnet.TelnetClient;
20
import org.apache.commons.net.telnet.TelnetClient;
21
import org.eclipse.core.runtime.IProgressMonitor;
20
22
21
public interface ITelnetSessionProvider {
23
public interface ITelnetSessionProvider {
22
	
24
	
23
	public TelnetClient getTelnetClient();
25
	/**
26
	 * Create a new Commons.Net TelnetClient.
27
	 * @param monitor progress monitor
28
	 * @return a new Commons.Net TelnetClient for the given connection, already authenticated
29
	 * @throws Exception in case of any error
30
	 */
31
	public TelnetClient makeNewTelnetClient(IProgressMonitor monitor) throws Exception ;
24
	
32
	
25
	/* Inform the connectorService that a session has been lost. */
26
	public void handleSessionLost();
27
}
33
}
(-)src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java (-12 / +17 lines)
Lines 14-19 Link Here
14
 * Contributors:
14
 * Contributors:
15
 * Martin Oberhuber (Wind River) - Adapted from LocalHostShell.
15
 * Martin Oberhuber (Wind River) - Adapted from LocalHostShell.
16
 * Sheldon D'souza (Celunite) - Adapted from SshHostShell
16
 * Sheldon D'souza (Celunite) - Adapted from SshHostShell
17
 * Sheldon D'souza (Celunite) - [187301] support multiple telnet shells
17
 *******************************************************************************/
18
 *******************************************************************************/
18
package org.eclipse.rse.internal.services.telnet.shell;
19
package org.eclipse.rse.internal.services.telnet.shell;
19
20
Lines 25-30 Link Here
25
import java.util.regex.Pattern;
26
import java.util.regex.Pattern;
26
27
27
import org.apache.commons.net.telnet.TelnetClient;
28
import org.apache.commons.net.telnet.TelnetClient;
29
import org.eclipse.core.runtime.NullProgressMonitor;
28
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
30
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
29
import org.eclipse.rse.services.clientserver.PathUtility;
31
import org.eclipse.rse.services.clientserver.PathUtility;
30
import org.eclipse.rse.services.shells.AbstractHostShell;
32
import org.eclipse.rse.services.shells.AbstractHostShell;
Lines 39-53 Link Here
39
	private TelnetShellOutputReader fStdoutHandler;
41
	private TelnetShellOutputReader fStdoutHandler;
40
	private TelnetShellOutputReader fStderrHandler;
42
	private TelnetShellOutputReader fStderrHandler;
41
	private TelnetShellWriterThread fShellWriter;
43
	private TelnetShellWriterThread fShellWriter;
44
	private TelnetClient fTelnetClient;
42
	
45
	
43
	public TelnetHostShell(ITelnetSessionProvider sessionProvider, String initialWorkingDirectory, String commandToRun, String encoding, String[] environment) {
46
	public TelnetHostShell(ITelnetSessionProvider sessionProvider, String initialWorkingDirectory, String commandToRun, String encoding, String[] environment) {
44
		try {
47
		try {
45
			fSessionProvider = sessionProvider;
48
			fSessionProvider = sessionProvider;
46
			
49
			
50
			fTelnetClient = fSessionProvider.makeNewTelnetClient(new NullProgressMonitor());
47
51
48
			fStdoutHandler = new TelnetShellOutputReader(this, new BufferedReader(new InputStreamReader(sessionProvider.getTelnetClient().getInputStream())), false);
52
			fStdoutHandler = new TelnetShellOutputReader(this, new BufferedReader(new InputStreamReader(fTelnetClient.getInputStream())), false);
49
			fStderrHandler = new TelnetShellOutputReader(this, null,true);
53
			fStderrHandler = new TelnetShellOutputReader(this, null,true);
50
			OutputStream outputStream = sessionProvider.getTelnetClient().getOutputStream();
54
			OutputStream outputStream = fTelnetClient.getOutputStream();
51
			//TODO check if encoding or command to execute needs to be considered
55
			//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
56
			//If a command is given, it might be possible to do without a Thread
53
			//Charset cs = Charset.forName(encoding);
57
			//Charset cs = Charset.forName(encoding);
Lines 85-95 Link Here
85
		try {
89
		try {
86
			//TODO disconnect should better be done via the ConnectorService!!
90
			//TODO disconnect should better be done via the ConnectorService!!
87
			//Because like we do it here, the connector service is not notified!
91
			//Because like we do it here, the connector service is not notified!
88
			TelnetClient client = fSessionProvider.getTelnetClient();
92
			if (fTelnetClient!=null) {
89
			if (client!=null) {
93
				synchronized(fTelnetClient) {
90
				synchronized(client) {
94
					if (fTelnetClient.isConnected())
91
					if (client.isConnected())
95
						fTelnetClient.disconnect();
92
						client.disconnect();
93
				}
96
				}
94
			}
97
			}
95
		} catch (IOException e) {
98
		} catch (IOException e) {
Lines 106-121 Link Here
106
	}
109
	}
107
110
108
	public boolean isActive() {
111
	public boolean isActive() {
109
		TelnetClient client = fSessionProvider.getTelnetClient();
112
		if (fTelnetClient!=null && fTelnetClient.isConnected()) {
110
		if (client!=null ) {
111
			return true;
113
			return true;
112
		}
114
		}
113
		// shell is not active: check for session lost
115
		// shell is not active: check for session lost
114
		exit();
116
		exit();
115
		
117
		
116
		if (client!=null && !client.isConnected()) {
118
		////MOB: Telnet sessions are really independent of each other.
117
			fSessionProvider.handleSessionLost();
119
		////So if one telnet session disconnects, it must not disconnect
118
		}
120
		////the other sessions.
121
		//if (fTelnetClient!=null && !fTelnetClient.isConnected()) {
122
		//	fSessionProvider.handleSessionLost();
123
		//}
119
		return false;
124
		return false;
120
	}
125
	}
121
126
(-)src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java (-40 / +61 lines)
Lines 14-25 Link Here
14
 * Sheldon D'souza (Celunite) - [186536] login and password should be configurable
14
 * Sheldon D'souza (Celunite) - [186536] login and password should be configurable
15
 * Sheldon D'souza (Celunite) - [186570] handle invalid user id and password more gracefully
15
 * Sheldon D'souza (Celunite) - [186570] handle invalid user id and password more gracefully
16
 * Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect() 
16
 * Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect() 
17
 * Sheldon D'souza (Celunite) - [187301] support multiple telnet shells
17
 *******************************************************************************/
18
 *******************************************************************************/
18
package org.eclipse.rse.internal.connectorservice.telnet;
19
package org.eclipse.rse.internal.connectorservice.telnet;
19
20
21
import java.io.IOException;
20
import java.io.InputStream;
22
import java.io.InputStream;
21
import java.io.PrintStream;
23
import java.io.PrintStream;
22
import java.lang.reflect.InvocationTargetException;
24
import java.lang.reflect.InvocationTargetException;
25
import java.util.ArrayList;
26
import java.util.Iterator;
27
import java.util.List;
23
28
24
import org.apache.commons.net.telnet.TelnetClient;
29
import org.apache.commons.net.telnet.TelnetClient;
25
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IProgressMonitor;
Lines 60-66 Link Here
60
65
61
	private static final int TELNET_DEFAULT_PORT = 23; // TODO Make configurable
66
	private static final int TELNET_DEFAULT_PORT = 23; // TODO Make configurable
62
	private static final int TELNET_CONNECT_TIMEOUT = 60; //seconds - TODO: Make configurable
67
	private static final int TELNET_CONNECT_TIMEOUT = 60; //seconds - TODO: Make configurable
63
	private TelnetClient fTelnetClient = new TelnetClient();
68
	private List fTelnetClients = new ArrayList();
64
	private SessionLostHandler fSessionLostHandler;
69
	private SessionLostHandler fSessionLostHandler;
65
	private InputStream in;
70
	private InputStream in;
66
	private PrintStream out;
71
	private PrintStream out;
Lines 109-114 Link Here
109
	}
114
	}
110
115
111
	protected void internalConnect(IProgressMonitor monitor) throws Exception {
116
	protected void internalConnect(IProgressMonitor monitor) throws Exception {
117
		try {
118
			TelnetClient client = makeNewTelnetClient(monitor);
119
			if( client != null ) {
120
				synchronized(this) {
121
					fTelnetClients.add(client);
122
					if (fSessionLostHandler==null) {
123
						fSessionLostHandler = new SessionLostHandler(this);
124
					}
125
				}
126
				notifyConnection();
127
			}
128
		}catch( Exception e) {
129
			if( e instanceof SystemMessageException ) {
130
				internalDisconnect( null );
131
				throw e;
132
			}
133
		}
134
	}
135
136
	public TelnetClient makeNewTelnetClient( IProgressMonitor monitor ) throws Exception {
137
		TelnetClient client = new TelnetClient();
112
		String host = getHostName();
138
		String host = getHostName();
113
		String user = getUserId();
139
		String user = getUserId();
114
		String password = ""; //$NON-NLS-1$
140
		String password = ""; //$NON-NLS-1$
Lines 116-129 Link Here
116
		Exception nestedException = null;
142
		Exception nestedException = null;
117
		try {
143
		try {
118
			Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
144
			Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
119
			fTelnetClient.connect(host, TELNET_DEFAULT_PORT);
145
			client.connect(host, TELNET_DEFAULT_PORT);
120
			SystemSignonInformation ssi = getSignonInformation();
146
			SystemSignonInformation ssi = getSignonInformation();
121
			if (ssi != null) {
147
			if (ssi != null) {
122
				password = ssi.getPassword();
148
				password = ssi.getPassword();
123
			}
149
			}
124
150
125
			in = fTelnetClient.getInputStream();
151
			in = client.getInputStream();
126
			out = new PrintStream(fTelnetClient.getOutputStream());
152
			out = new PrintStream(client.getOutputStream());
127
153
128
			long millisToEnd = System.currentTimeMillis() + TELNET_CONNECT_TIMEOUT*1000;
154
			long millisToEnd = System.currentTimeMillis() + TELNET_CONNECT_TIMEOUT*1000;
129
			LoginThread checkLogin = new LoginThread(user, password);
155
			LoginThread checkLogin = new LoginThread(user, password);
Lines 156-165 Link Here
156
		} finally {
182
		} finally {
157
			if (status == CONNECT_CANCELED) {
183
			if (status == CONNECT_CANCELED) {
158
				Activator.trace("Telnet Service: Canceled"); //$NON-NLS-1$
184
				Activator.trace("Telnet Service: Canceled"); //$NON-NLS-1$
159
				sessionDisconnect(); //will eventually destroy the LoginThread
185
				try {
186
					client.disconnect(); //will eventually destroy the LoginThread
187
				} catch(Exception e) {
188
					/*ignore on forced disconnect*/
189
				}
190
				client = null;
160
			} else if (status == SUCCESS_CODE) {
191
			} else if (status == SUCCESS_CODE) {
161
				fSessionLostHandler = new SessionLostHandler(this);
162
				notifyConnection();
163
				Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
192
				Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
164
			} else {
193
			} else {
165
				Activator.trace("Telnet Service: Connect failed"); //$NON-NLS-1$
194
				Activator.trace("Telnet Service: Connect failed"); //$NON-NLS-1$
Lines 173-182 Link Here
173
					msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_AUTH_FAILED);
202
					msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_AUTH_FAILED);
174
					msg.makeSubstitution(getHost().getAliasName());
203
					msg.makeSubstitution(getHost().getAliasName());
175
				}
204
				}
176
				internalDisconnect(null);
177
				throw new SystemMessageException(msg);
205
				throw new SystemMessageException(msg);
178
			}
206
			}
179
		}
207
		}
208
		return client;
180
	}
209
	}
181
210
182
	/**
211
	/**
Lines 185-202 Link Here
185
	 */
214
	 */
186
	private synchronized void sessionDisconnect() {
215
	private synchronized void sessionDisconnect() {
187
		Activator.trace("TelnetConnectorService.sessionDisconnect"); //$NON-NLS-1$
216
		Activator.trace("TelnetConnectorService.sessionDisconnect"); //$NON-NLS-1$
188
		try {
217
		Iterator it = fTelnetClients.iterator();
189
			if (fTelnetClient != null) {
218
		while (it.hasNext()) {
190
				synchronized (fTelnetClient) {
219
			TelnetClient client = (TelnetClient)it.next();
191
					if (fTelnetClient.isConnected())
220
			if (client.isConnected()) {
192
						fTelnetClient.disconnect();
221
				try {
222
					client.disconnect();
223
				} catch(IOException e) {
224
					// Avoid NPE on disconnect shown in UI
225
					// This is a non-critical exception so print only in debug mode
226
					if (Activator.isTracingOn())
227
						e.printStackTrace();
193
				}
228
				}
194
			}
229
			}
195
		} catch (Exception e) {
230
			it.remove();
196
			// Avoid NPE on disconnect shown in UI
197
			// This is a non-critical exception so print only in debug mode
198
			if (Activator.isTracingOn())
199
				e.printStackTrace();
200
		}
231
		}
201
	}
232
	}
202
233
Lines 267-276 Link Here
267
		notifyDisconnection();
298
		notifyDisconnection();
268
	}
299
	}
269
300
270
	public TelnetClient getTelnetClient() {
271
		return fTelnetClient;
272
	}
273
274
	/**
301
	/**
275
	 * Handle session-lost events. This is generic for any sort of connector
302
	 * Handle session-lost events. This is generic for any sort of connector
276
	 * service. Most of this is extracted from dstore's
303
	 * service. Most of this is extracted from dstore's
Lines 514-531 Link Here
514
		}
541
		}
515
	}
542
	}
516
543
517
	/*
518
	 * Notification from sub-services that our session was lost. Notify all
519
	 * subsystems properly.
520
	 * TODO allow user to try and reconnect?
521
	 */
522
	public void handleSessionLost() {
523
		Activator.trace("TelnetConnectorService: handleSessionLost"); //$NON-NLS-1$
524
		if (fSessionLostHandler != null) {
525
			fSessionLostHandler.sessionLost();
526
		}
527
	}
528
529
	protected static Display getStandardDisplay() {
544
	protected static Display getStandardDisplay() {
530
		Display display = Display.getCurrent();
545
		Display display = Display.getCurrent();
531
		if (display == null) {
546
		if (display == null) {
Lines 535-551 Link Here
535
	}
550
	}
536
551
537
	public boolean isConnected() {
552
	public boolean isConnected() {
538
		boolean connected = false;
553
		boolean anyConnected = false;
539
		if (fTelnetClient != null) {
554
		synchronized(this) {
540
			synchronized (fTelnetClient) {
555
			Iterator it = fTelnetClients.iterator();
541
				connected = fTelnetClient.isConnected();
556
			while (it.hasNext()) {
557
				TelnetClient client = (TelnetClient)it.next();
558
				if (client.isConnected()) {
559
					anyConnected = true;
560
				} else {
561
					it.remove();
562
				}
542
			}
563
			}
543
		}
564
		}
544
		if (!connected && fSessionLostHandler != null) {
565
		if (!anyConnected && fSessionLostHandler != null) {
545
			Activator.trace("TelnetConnectorService.isConnected: false -> sessionLost"); //$NON-NLS-1$
566
			Activator.trace("TelnetConnectorService.isConnected: false -> sessionLost"); //$NON-NLS-1$
546
			fSessionLostHandler.sessionLost();
567
			fSessionLostHandler.sessionLost();
547
		}
568
		}
548
		return connected;
569
		return anyConnected;
549
	}
570
	}
550
571
551
	/**
572
	/**

Return to bug 187301