|
Lines 13-25
Link Here
|
| 13 |
* Martin Oberhuber (Wind River) - [178606] fix endless loop in readUntil() |
13 |
* Martin Oberhuber (Wind River) - [178606] fix endless loop in readUntil() |
| 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() |
|
|
| 17 |
*******************************************************************************/ |
16 |
*******************************************************************************/ |
| 18 |
package org.eclipse.rse.internal.connectorservice.telnet; |
17 |
package org.eclipse.rse.internal.connectorservice.telnet; |
| 19 |
|
18 |
|
|
|
19 |
import java.io.IOException; |
| 20 |
import java.io.InputStream; |
20 |
import java.io.InputStream; |
| 21 |
import java.io.PrintStream; |
21 |
import java.io.PrintStream; |
|
|
22 |
import java.lang.reflect.Array; |
| 22 |
import java.lang.reflect.InvocationTargetException; |
23 |
import java.lang.reflect.InvocationTargetException; |
|
|
24 |
import java.net.SocketException; |
| 25 |
import java.util.ArrayList; |
| 26 |
import java.util.HashMap; |
| 27 |
import java.util.List; |
| 28 |
import java.util.Map; |
| 29 |
import java.util.Vector; |
| 23 |
|
30 |
|
| 24 |
import org.apache.commons.net.telnet.TelnetClient; |
31 |
import org.apache.commons.net.telnet.TelnetClient; |
| 25 |
import org.eclipse.core.runtime.IProgressMonitor; |
32 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
Lines 28-33
Link Here
|
| 28 |
import org.eclipse.jface.operation.IRunnableContext; |
35 |
import org.eclipse.jface.operation.IRunnableContext; |
| 29 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
36 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
| 30 |
import org.eclipse.rse.core.RSECorePlugin; |
37 |
import org.eclipse.rse.core.RSECorePlugin; |
|
|
38 |
import org.eclipse.rse.core.SystemBasePlugin; |
| 31 |
import org.eclipse.rse.core.model.IHost; |
39 |
import org.eclipse.rse.core.model.IHost; |
| 32 |
import org.eclipse.rse.core.model.IPropertySet; |
40 |
import org.eclipse.rse.core.model.IPropertySet; |
| 33 |
import org.eclipse.rse.core.model.ISystemRegistry; |
41 |
import org.eclipse.rse.core.model.ISystemRegistry; |
|
Lines 41-47
Link Here
|
| 41 |
import org.eclipse.rse.services.clientserver.messages.SystemMessageException; |
49 |
import org.eclipse.rse.services.clientserver.messages.SystemMessageException; |
| 42 |
import org.eclipse.rse.ui.ISystemMessages; |
50 |
import org.eclipse.rse.ui.ISystemMessages; |
| 43 |
import org.eclipse.rse.ui.RSEUIPlugin; |
51 |
import org.eclipse.rse.ui.RSEUIPlugin; |
| 44 |
import org.eclipse.rse.ui.SystemBasePlugin; |
|
|
| 45 |
import org.eclipse.rse.ui.messages.SystemMessageDialog; |
52 |
import org.eclipse.rse.ui.messages.SystemMessageDialog; |
| 46 |
import org.eclipse.rse.ui.subsystems.StandardConnectorService; |
53 |
import org.eclipse.rse.ui.subsystems.StandardConnectorService; |
| 47 |
import org.eclipse.swt.widgets.Display; |
54 |
import org.eclipse.swt.widgets.Display; |
|
Lines 57-69
Link Here
|
| 57 |
public static final String PROPERTY_LOGIN_PROMPT = "Login.Prompt"; //$NON-NLS-1$ |
64 |
public static final String PROPERTY_LOGIN_PROMPT = "Login.Prompt"; //$NON-NLS-1$ |
| 58 |
public static final String PROPERTY_PASSWORD_PROMPT = "Password.Prompt"; //$NON-NLS-1$ |
65 |
public static final String PROPERTY_PASSWORD_PROMPT = "Password.Prompt"; //$NON-NLS-1$ |
| 59 |
public static final String PROPERTY_COMMAND_PROMPT = "Command.Prompt"; //$NON-NLS-1$ |
66 |
public static final String PROPERTY_COMMAND_PROMPT = "Command.Prompt"; //$NON-NLS-1$ |
| 60 |
|
67 |
public static final String PROPERTY_TELNET_CONNECT_TIMEOUT = "Telnet.timeout"; //$NON-NLS-1$ |
| 61 |
private static final int TELNET_DEFAULT_PORT = 23; // TODO Make configurable |
|
|
| 62 |
private static final int TELNET_CONNECT_TIMEOUT = 60; //seconds - TODO: Make configurable |
68 |
private static final int TELNET_CONNECT_TIMEOUT = 60; //seconds - TODO: Make configurable |
|
|
69 |
|
| 70 |
private static final int TELNET_DEFAULT_PORT = 23; |
| 63 |
private TelnetClient fTelnetClient = new TelnetClient(); |
71 |
private TelnetClient fTelnetClient = new TelnetClient(); |
|
|
72 |
private Map fTelnetShellClients = new HashMap(); |
| 73 |
private Vector shellSessionId = new Vector(); |
| 64 |
private SessionLostHandler fSessionLostHandler; |
74 |
private SessionLostHandler fSessionLostHandler; |
| 65 |
private InputStream in; |
75 |
private InputStream in; |
| 66 |
private PrintStream out; |
76 |
private PrintStream out; |
|
|
77 |
private String sessionHostName ; |
| 78 |
private String sessionPassword; |
| 67 |
private IPropertySet telnetPropertySet = null; |
79 |
private IPropertySet telnetPropertySet = null; |
| 68 |
private static final int ERROR_CODE = 100; // filed error code |
80 |
private static final int ERROR_CODE = 100; // filed error code |
| 69 |
private static final int SUCCESS_CODE = 150; // login pass code |
81 |
private static final int SUCCESS_CODE = 150; // login pass code |
|
Lines 99-104
Link Here
|
| 99 |
"assword: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$ |
111 |
"assword: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$ |
| 100 |
telnetSet.addProperty(PROPERTY_COMMAND_PROMPT, |
112 |
telnetSet.addProperty(PROPERTY_COMMAND_PROMPT, |
| 101 |
"$", PropertyType.getStringPropertyType()); //$NON-NLS-1$ |
113 |
"$", PropertyType.getStringPropertyType()); //$NON-NLS-1$ |
|
|
114 |
telnetSet.addProperty(PROPERTY_TELNET_CONNECT_TIMEOUT, |
| 115 |
"60", PropertyType.getStringPropertyType()); //$NON-NLS-1$ |
| 116 |
|
| 102 |
} |
117 |
} |
| 103 |
return telnetSet; |
118 |
return telnetSet; |
| 104 |
} |
119 |
} |
|
Lines 112-117
Link Here
|
| 112 |
String host = getHostName(); |
127 |
String host = getHostName(); |
| 113 |
String user = getUserId(); |
128 |
String user = getUserId(); |
| 114 |
String password = ""; //$NON-NLS-1$ |
129 |
String password = ""; //$NON-NLS-1$ |
|
|
130 |
|
| 115 |
int status = ERROR_CODE; |
131 |
int status = ERROR_CODE; |
| 116 |
Exception nestedException = null; |
132 |
Exception nestedException = null; |
| 117 |
try { |
133 |
try { |
|
Lines 122-131
Link Here
|
| 122 |
password = ssi.getPassword(); |
138 |
password = ssi.getPassword(); |
| 123 |
} |
139 |
} |
| 124 |
|
140 |
|
|
|
141 |
telnetPropertySet = getTelnetPropertySet(); |
| 142 |
|
| 143 |
String time_out = telnetPropertySet.getPropertyValue(PROPERTY_TELNET_CONNECT_TIMEOUT); |
| 144 |
this.sessionHostName = host; |
| 145 |
this.sessionPassword = password; |
| 125 |
in = fTelnetClient.getInputStream(); |
146 |
in = fTelnetClient.getInputStream(); |
| 126 |
out = new PrintStream(fTelnetClient.getOutputStream()); |
147 |
out = new PrintStream(fTelnetClient.getOutputStream()); |
| 127 |
|
148 |
|
| 128 |
long millisToEnd = System.currentTimeMillis() + TELNET_CONNECT_TIMEOUT*1000; |
149 |
long millisToEnd = System.currentTimeMillis() + Integer.valueOf( time_out ).intValue()*1000; |
| 129 |
LoginThread checkLogin = new LoginThread(user, password); |
150 |
LoginThread checkLogin = new LoginThread(user, password); |
| 130 |
checkLogin.start(); |
151 |
checkLogin.start(); |
| 131 |
while (checkLogin.isAlive() && System.currentTimeMillis()<millisToEnd) { |
152 |
while (checkLogin.isAlive() && System.currentTimeMillis()<millisToEnd) { |
|
Lines 188-195
Link Here
|
| 188 |
try { |
209 |
try { |
| 189 |
if (fTelnetClient != null) { |
210 |
if (fTelnetClient != null) { |
| 190 |
synchronized (fTelnetClient) { |
211 |
synchronized (fTelnetClient) { |
|
|
212 |
|
| 191 |
if (fTelnetClient.isConnected()) |
213 |
if (fTelnetClient.isConnected()) |
| 192 |
fTelnetClient.disconnect(); |
214 |
fTelnetClient.disconnect(); |
|
|
215 |
|
| 216 |
for( int i=0;i<shellSessionId.size();i++) { |
| 217 |
|
| 218 |
Object client = fTelnetShellClients.get( shellSessionId.get( i )); |
| 219 |
if( client != null ) { |
| 220 |
if( client instanceof TelnetClient) { |
| 221 |
if(((TelnetClient) client).isConnected()) { |
| 222 |
((TelnetClient)client).disconnect(); |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 193 |
} |
227 |
} |
| 194 |
} |
228 |
} |
| 195 |
} catch (Exception e) { |
229 |
} catch (Exception e) { |
|
Lines 250-256
Link Here
|
| 250 |
Activator.trace("Telnet Service: Disconnecting ....."); //$NON-NLS-1$ |
284 |
Activator.trace("Telnet Service: Disconnecting ....."); //$NON-NLS-1$ |
| 251 |
|
285 |
|
| 252 |
boolean sessionLost = (fSessionLostHandler != null && fSessionLostHandler.isSessionLost()); |
286 |
boolean sessionLost = (fSessionLostHandler != null && fSessionLostHandler.isSessionLost()); |
| 253 |
// no more interested in handling session-lost, since we are |
287 |
// no more interested in handling session-lost, sinkeyce we are |
| 254 |
// disconnecting anyway |
288 |
// disconnecting anyway |
| 255 |
fSessionLostHandler = null; |
289 |
fSessionLostHandler = null; |
| 256 |
// handle events |
290 |
// handle events |
|
Lines 268-276
Link Here
|
| 268 |
} |
302 |
} |
| 269 |
|
303 |
|
| 270 |
public TelnetClient getTelnetClient() { |
304 |
public TelnetClient getTelnetClient() { |
|
|
305 |
|
| 271 |
return fTelnetClient; |
306 |
return fTelnetClient; |
| 272 |
} |
307 |
} |
| 273 |
|
308 |
|
|
|
309 |
public IPropertySet getSessionPropertySet() { |
| 310 |
return this.telnetPropertySet; |
| 311 |
} |
| 312 |
|
| 313 |
public String getSessionHostName() { |
| 314 |
return this.sessionHostName; |
| 315 |
} |
| 316 |
|
| 317 |
public String getSessionUsername() { |
| 318 |
return getUserId(); |
| 319 |
} |
| 320 |
|
| 321 |
public String getSessionPassword() { |
| 322 |
return this.sessionPassword; |
| 323 |
} |
| 324 |
|
| 325 |
public void addShellsTelnetClient( TelnetClient client , String shellId) { |
| 326 |
this.shellSessionId.add( shellId ); |
| 327 |
this.fTelnetShellClients.put(shellId, client); |
| 328 |
} |
| 329 |
|
| 330 |
public void removeShellsTelnetClient( String shellId ) { |
| 331 |
this.fTelnetShellClients.remove(shellId); |
| 332 |
} |
| 333 |
|
| 274 |
/** |
334 |
/** |
| 275 |
* Handle session-lost events. This is generic for any sort of connector |
335 |
* Handle session-lost events. This is generic for any sort of connector |
| 276 |
* service. Most of this is extracted from dstore's |
336 |
* service. Most of this is extracted from dstore's |