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