diff --git a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java index 55486d1945c..3a31f6d76cf 100644 --- a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java @@ -18,6 +18,7 @@ * Martin Oberhuber (Wind River) - [168197] Replace JFace MessagDialog by SWT MessageBox * Martin Oberhuber (Wind River) - [205674][ssh] Terminal remains "connecting" when authentication is cancelled * Michael Scharf (Wind River) - 240420: [terminal][ssh]Channel is not closed when the connection is closed with the close button + * Martin Oberhuber (Wind River) - [206919] Improve SSH Terminal Error Reporting *******************************************************************************/ package org.eclipse.tm.internal.terminal.ssh; @@ -30,6 +31,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.jface.window.Window; import org.eclipse.jsch.core.IJSchService; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; @@ -90,13 +92,16 @@ class SshConnection extends Thread { //---------------------------------------------------------------------- public void run() { + boolean connectSucceeded = false; + String host = ""; //$NON-NLS-1$ + int port = 22; try { int nTimeout = fConn.getSshSettings().getTimeout() * 1000; int nKeepalive = fConn.getSshSettings().getKeepalive() * 1000; - String host = fConn.getSshSettings().getHost(); + host = fConn.getSshSettings().getHost(); String user = fConn.getSshSettings().getUser(); String password = fConn.getSshSettings().getPassword(); - int port = fConn.getSshSettings().getPort(); + port = fConn.getSshSettings().getPort(); ////Giving a connectionId could be the index into a local ////Store where passwords are stored @@ -136,6 +141,7 @@ class SshConnection extends Thread { // maybe the terminal was disconnected while we were connecting if (isSessionConnected() && channel.isConnected()) { + connectSucceeded = true; fConn.setInputStream(channel.getInputStream()); fConn.setOutputStream(channel.getOutputStream()); fConn.setChannel(channel); @@ -148,7 +154,27 @@ class SshConnection extends Thread { } } } catch (Exception e) { - connectFailed(e.getMessage(),e.getMessage()); + Throwable cause = e; + while (cause.getCause() != null) { + cause = cause.getCause(); + } + String origMsg = cause.getMessage(); + String msg = SshMessages.getMessageFor(cause); + if ((cause instanceof JSchException) && origMsg != null && origMsg.startsWith("Auth")) { //$NON-NLS-1$ + if (origMsg.indexOf("cancel") >= 0) { //$NON-NLS-1$ + msg = SshMessages.SSH_AUTH_CANCEL; + } else if (origMsg.indexOf("fail") >= 0) { //$NON-NLS-1$ + msg = SshMessages.SSH_AUTH_FAIL; + } + } + if (!connectSucceeded) { + String hostPort = host; + if (port != 22) { + hostPort = hostPort + ':' + port; + } + msg = NLS.bind(SshMessages.ERROR_CONNECTING, hostPort, msg); + } + connectFailed(msg, msg); } finally { // make sure the terminal is disconnected when the thread ends try { @@ -331,6 +357,7 @@ class SshConnection extends Thread { private void connectFailed(String terminalText, String msg) { Logger.log(terminalText); fControl.displayTextInTerminal(terminalText); - fControl.setMsg(msg); + // fControl.setMsg(msg); } + } \ No newline at end of file diff --git a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java index d24753a17bb..85a1a0fd1cd 100644 --- a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java @@ -1,17 +1,20 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: + * Copyright (c) 2000, 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives + * Martin Oberhuber (Wind River) - [206919] Improve SSH Terminal Error Reporting (Adopting code from org.eclipse.team.cvs.core) *******************************************************************************/ package org.eclipse.tm.internal.terminal.ssh; +import java.lang.reflect.Field; + import org.eclipse.osgi.util.NLS; public class SshMessages extends NLS { @@ -27,7 +30,7 @@ public class SshMessages extends NLS { public static String KEEPALIVE_Tooltip; public static String WARNING; public static String INFO; - + //These are from org.eclipse.team.cvs.ui.CVSUIMessages public static String UserValidationDialog_required; public static String UserValidationDialog_labelUser; @@ -41,4 +44,54 @@ public class SshMessages extends NLS { public static String KeyboardInteractiveDialog_message; public static String KeyboardInteractiveDialog_labelConnection; + public static String ERROR_CONNECTING; + public static String TerminalCommunicationException_io; + public static String SSH_AUTH_CANCEL; + public static String SSH_AUTH_FAIL; + public static String com_jcraft_jsch_JSchException; + public static String java_io_IOException; + public static String java_io_EOFException; + public static String java_io_InterruptedIOException; + public static String java_net_UnknownHostException; + public static String java_net_ConnectException; + public static String java_net_SocketException; + public static String java_net_NoRouteToHostException; + + // + + public static String getMessageFor(Throwable throwable) { + String message = getMessage(getMessageKey(throwable)); + if (message == null) { + message = NLS.bind(SshMessages.TerminalCommunicationException_io, (new Object[] { throwable.toString() })); + } else { + message = NLS.bind(message, (new Object[] { throwable.getMessage() })); + } + return message; + } + + private static String getMessageKey(Throwable t) { + String name = t.getClass().getName(); + name = name.replace('.', '_'); + return name; + } + + // + // + + public static String getMessage(String key) { + try { + Field f = SshMessages.class.getDeclaredField(key); + Object o = f.get(null); + if (o instanceof String) + return (String) o; + } catch (SecurityException e) { + } catch (NoSuchFieldException e) { + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } + return null; + } + + // + } diff --git a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties index b2f0806a9a3..9198ae1c8b6 100644 --- a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. +# Copyright (c) 2000, 2008 Wind River Systems, Inc. and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -9,7 +9,11 @@ # Michael Scharf (Wind River) - initial API and implementation # Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives +# Martin Oberhuber (Wind River) - [206919] Improve SSH Terminal Error Reporting (Adopting code from org.eclipse.team.cvs.core) ############################################################################### + +# NLS_MESSAGEFORMAT_VAR + HOST = Host USER = User PORT = Port @@ -32,3 +36,17 @@ UserValidationDialog_7=Saved passwords are stored on your computer in a file tha KeyboardInteractiveDialog_message=Keyboard Interactive authentication for {0} KeyboardInteractiveDialog_labelConnection=Enter values for the following connection: {0} + +#These are from org.eclipse.team.cvs.core/messages.properties (c) IBM 2000, 2007 +ERROR_CONNECTING=Error connecting {0} : {2} +TerminalCommunicationException_io=Communication error: {0} +SSH_AUTH_CANCEL=SSH Authentication cancelled. +SSH_AUTH_FAIL=SSH Authentication failed. +com_jcraft_jsch_JSchException=SSH client error: {0} +java_io_IOException=I/O exception occurred: {0} +java_io_EOFException=End of file encountered: {0} +java_io_InterruptedIOException=I/O has been interrupted. +java_net_UnknownHostException=Cannot locate host: {0} +java_net_ConnectException=Cannot connect to host: {0} +java_net_SocketException=Socket Exception: {0} +java_net_NoRouteToHostException={0}