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/connectorservice/telnet/TelnetConnectorService.java (-64 / +87 lines)
Lines 23-28 Link Here
23
23
24
import org.apache.commons.net.telnet.TelnetClient;
24
import org.apache.commons.net.telnet.TelnetClient;
25
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.NullProgressMonitor;
26
import org.eclipse.core.runtime.OperationCanceledException;
27
import org.eclipse.core.runtime.OperationCanceledException;
27
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
28
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
28
import org.eclipse.jface.operation.IRunnableContext;
29
import org.eclipse.jface.operation.IRunnableContext;
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 109-180 Link Here
109
	}
110
	}
110
111
111
	protected void internalConnect(IProgressMonitor monitor) throws Exception {
112
	protected void internalConnect(IProgressMonitor monitor) throws Exception {
112
		String host = getHostName();
113
		
113
		String user = getUserId();
114
		String password = ""; //$NON-NLS-1$
115
		int status = ERROR_CODE;
116
		Exception nestedException = null;
117
		try {
114
		try {
118
			Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
115
			
119
			fTelnetClient.connect(host, TELNET_DEFAULT_PORT);
116
			TelnetClient client = makeNewTelnetClient(monitor);
120
			SystemSignonInformation ssi = getSignonInformation();
117
			if( client != null ) {
121
			if (ssi != null) {
118
				fTelnetClient = client;
122
				password = ssi.getPassword();
123
			}
124
125
			in = fTelnetClient.getInputStream();
126
			out = new PrintStream(fTelnetClient.getOutputStream());
127
128
			long millisToEnd = System.currentTimeMillis() + TELNET_CONNECT_TIMEOUT*1000;
129
			LoginThread checkLogin = new LoginThread(user, password);
130
			checkLogin.start();
131
			while (checkLogin.isAlive() && System.currentTimeMillis()<millisToEnd) {
132
				if (monitor!=null) {
133
					monitor.worked(1);
134
					if (monitor.isCanceled()) {
135
						status = CONNECT_CANCELED;
136
						//Thread will be interrupted by sessionDisconnect()
137
						//checkLogin.interrupt();
138
						break;
139
					}
140
				}
141
				Display d = Display.getCurrent();
142
				if (d!=null) {
143
					while(d.readAndDispatch()) {
144
						//get next event if on dispatch thread
145
					}
146
				}
147
				checkLogin.join(500);
148
			}
149
			if (status != CONNECT_CANCELED) {
150
				status = checkLogin.getLoginStatus();
151
				checkLogin.join();
152
			}
153
		} catch (Exception e) {
154
			Activator.trace("Telnet Service failed: " + e.toString()); //$NON-NLS-1$
155
			nestedException = e;
156
		} finally {
157
			if (status == CONNECT_CANCELED) {
158
				Activator.trace("Telnet Service: Canceled"); //$NON-NLS-1$
159
				sessionDisconnect(); //will eventually destroy the LoginThread
160
			} else if (status == SUCCESS_CODE) {
161
				fSessionLostHandler = new SessionLostHandler(this);
119
				fSessionLostHandler = new SessionLostHandler(this);
162
				notifyConnection();
120
				notifyConnection();
163
				Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
121
			}
164
			} else {
122
		}catch( Exception e) {
165
				Activator.trace("Telnet Service: Connect failed"); //$NON-NLS-1$
123
			
166
				//TODO pass the nested exception as well as original prompts
124
			if( e instanceof SystemMessageException ) {
167
				//from the remote side with the SystemMessageException for user diagnostics
125
				internalDisconnect( null );
168
				SystemMessage msg;
126
				throw e;
169
				if (nestedException!=null) {
170
					msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_EXCEPTION_OCCURRED);
171
					msg.makeSubstitution(nestedException);
172
				} else {
173
					msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_AUTH_FAILED);
174
					msg.makeSubstitution(getHost().getAliasName());
175
				}
176
				internalDisconnect(null);
177
				throw new SystemMessageException(msg);
178
			}
127
			}
179
		}
128
		}
180
	}
129
	}
Lines 265-275 Link Here
265
214
266
		// Fire comm event to signal state changed
215
		// Fire comm event to signal state changed
267
		notifyDisconnection();
216
		notifyDisconnection();
217
		clearPassword(false,true);
268
	}
218
	}
269
219
270
	public TelnetClient getTelnetClient() {
220
	public TelnetClient getTelnetClient() {
271
		return fTelnetClient;
221
		return fTelnetClient;
272
	}
222
	}
223
	
224
	public TelnetClient makeNewTelnetClient( IProgressMonitor monitor ) throws Exception{
225
		
226
		TelnetClient client = new TelnetClient();
227
		String host = getHostName();
228
		String user = getUserId();
229
		String password = ""; //$NON-NLS-1$
230
		int status = ERROR_CODE;
231
		Exception nestedException = null;
232
		try {
233
			Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
234
			client.connect(host, TELNET_DEFAULT_PORT);
235
			SystemSignonInformation ssi = getSignonInformation();
236
			if (ssi != null) {
237
				password = ssi.getPassword();
238
			}
239
240
			in = client.getInputStream();
241
			out = new PrintStream(client.getOutputStream());
242
243
			long millisToEnd = System.currentTimeMillis() + TELNET_CONNECT_TIMEOUT*1000;
244
			LoginThread checkLogin = new LoginThread(user, password);
245
			checkLogin.start();
246
			while (checkLogin.isAlive() && System.currentTimeMillis()<millisToEnd) {
247
				if (monitor!=null) {
248
					monitor.worked(1);
249
					if (monitor.isCanceled()) {
250
						status = CONNECT_CANCELED;
251
						//Thread will be interrupted by sessionDisconnect()
252
						//checkLogin.interrupt();
253
						break;
254
					}
255
				}
256
				Display d = Display.getCurrent();
257
				if (d!=null) {
258
					while(d.readAndDispatch()) {
259
						//get next event if on dispatch thread
260
					}
261
				}
262
				checkLogin.join(500);
263
			}
264
			if (status != CONNECT_CANCELED) {
265
				status = checkLogin.getLoginStatus();
266
				checkLogin.join();
267
			}
268
		} catch (Exception e) {
269
			Activator.trace("Telnet Service failed: " + e.toString()); //$NON-NLS-1$
270
			nestedException = e;
271
		} finally {
272
			if (status == CONNECT_CANCELED) {
273
				Activator.trace("Telnet Service: Canceled"); //$NON-NLS-1$
274
				sessionDisconnect(); //will eventually destroy the LoginThread
275
				client = null;
276
			} else if (status == SUCCESS_CODE) {
277
				Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
278
			} else {
279
				Activator.trace("Telnet Service: Connect failed"); //$NON-NLS-1$
280
				//TODO pass the nested exception as well as original prompts
281
				//from the remote side with the SystemMessageException for user diagnostics
282
				SystemMessage msg;
283
				if (nestedException!=null) {
284
					msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_EXCEPTION_OCCURRED);
285
					msg.makeSubstitution(nestedException);
286
				} else {
287
					msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_AUTH_FAILED);
288
					msg.makeSubstitution(getHost().getAliasName());
289
				}
290
				client = null;
291
				throw new SystemMessageException(msg);
292
			}
293
		}
294
		return client;
295
	}
273
296
274
	/**
297
	/**
275
	 * Handle session-lost events. This is generic for any sort of connector
298
	 * Handle session-lost events. This is generic for any sort of connector
(-)src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java (-10 / +11 lines)
Lines 25-30 Link Here
25
import java.util.regex.Pattern;
25
import java.util.regex.Pattern;
26
26
27
import org.apache.commons.net.telnet.TelnetClient;
27
import org.apache.commons.net.telnet.TelnetClient;
28
import org.eclipse.core.runtime.NullProgressMonitor;
28
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
29
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
29
import org.eclipse.rse.services.clientserver.PathUtility;
30
import org.eclipse.rse.services.clientserver.PathUtility;
30
import org.eclipse.rse.services.shells.AbstractHostShell;
31
import org.eclipse.rse.services.shells.AbstractHostShell;
Lines 39-53 Link Here
39
	private TelnetShellOutputReader fStdoutHandler;
40
	private TelnetShellOutputReader fStdoutHandler;
40
	private TelnetShellOutputReader fStderrHandler;
41
	private TelnetShellOutputReader fStderrHandler;
41
	private TelnetShellWriterThread fShellWriter;
42
	private TelnetShellWriterThread fShellWriter;
43
	private TelnetClient fTelnetClient;
42
	
44
	
43
	public TelnetHostShell(ITelnetSessionProvider sessionProvider, String initialWorkingDirectory, String commandToRun, String encoding, String[] environment) {
45
	public TelnetHostShell(ITelnetSessionProvider sessionProvider, String initialWorkingDirectory, String commandToRun, String encoding, String[] environment) {
44
		try {
46
		try {
45
			fSessionProvider = sessionProvider;
47
			fSessionProvider = sessionProvider;
46
			
48
			
49
			fTelnetClient = fSessionProvider.makeNewTelnetClient( new NullProgressMonitor());
47
50
48
			fStdoutHandler = new TelnetShellOutputReader(this, new BufferedReader(new InputStreamReader(sessionProvider.getTelnetClient().getInputStream())), false);
51
			fStdoutHandler = new TelnetShellOutputReader(this, new BufferedReader(new InputStreamReader(fTelnetClient.getInputStream())), false);
49
			fStderrHandler = new TelnetShellOutputReader(this, null,true);
52
			fStderrHandler = new TelnetShellOutputReader(this, null,true);
50
			OutputStream outputStream = sessionProvider.getTelnetClient().getOutputStream();
53
			OutputStream outputStream = fTelnetClient.getOutputStream();
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 85-95 Link Here
85
		try {
88
		try {
86
			//TODO disconnect should better be done via the ConnectorService!!
89
			//TODO disconnect should better be done via the ConnectorService!!
87
			//Because like we do it here, the connector service is not notified!
90
			//Because like we do it here, the connector service is not notified!
88
			TelnetClient client = fSessionProvider.getTelnetClient();
91
			if (fTelnetClient!=null) {
89
			if (client!=null) {
92
				synchronized(fTelnetClient) {
90
				synchronized(client) {
93
					if (fTelnetClient.isConnected())
91
					if (client.isConnected())
94
						fTelnetClient.disconnect();
92
						client.disconnect();
93
				}
95
				}
94
			}
96
			}
95
		} catch (IOException e) {
97
		} catch (IOException e) {
Lines 106-119 Link Here
106
	}
108
	}
107
109
108
	public boolean isActive() {
110
	public boolean isActive() {
109
		TelnetClient client = fSessionProvider.getTelnetClient();
111
		if (fTelnetClient!=null ) {
110
		if (client!=null ) {
111
			return true;
112
			return true;
112
		}
113
		}
113
		// shell is not active: check for session lost
114
		// shell is not active: check for session lost
114
		exit();
115
		exit();
115
		
116
		
116
		if (client!=null && !client.isConnected()) {
117
		if (fTelnetClient!=null && !fTelnetClient.isConnected()) {
117
			fSessionProvider.handleSessionLost();
118
			fSessionProvider.handleSessionLost();
118
		}
119
		}
119
		return false;
120
		return false;
(-)src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java (+3 lines)
Lines 17-27 Link Here
17
package org.eclipse.rse.internal.services.telnet;
17
package org.eclipse.rse.internal.services.telnet;
18
18
19
import org.apache.commons.net.telnet.TelnetClient;
19
import org.apache.commons.net.telnet.TelnetClient;
20
import org.eclipse.core.runtime.IProgressMonitor;
20
21
21
public interface ITelnetSessionProvider {
22
public interface ITelnetSessionProvider {
22
	
23
	
23
	public TelnetClient getTelnetClient();
24
	public TelnetClient getTelnetClient();
24
	
25
	
26
	public TelnetClient makeNewTelnetClient( IProgressMonitor monitor) throws Exception ;
27
	
25
	/* Inform the connectorService that a session has been lost. */
28
	/* Inform the connectorService that a session has been lost. */
26
	public void handleSessionLost();
29
	public void handleSessionLost();
27
}
30
}

Return to bug 187301