|
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 |
/** |