com.foxsmart.ic.net
Class MindTermSshProtocolHandlerImpl

java.lang.Object
  extended by com.foxsmart.ic.net.AbstractCliProtocolHandler
      extended by com.foxsmart.ic.net.MindTermSshProtocolHandlerImpl
All Implemented Interfaces:
CliProtocolHandler, ProtocolHandler

public class MindTermSshProtocolHandlerImpl
extends AbstractCliProtocolHandler

The MindTermSshProtocolHandler class helps with the handling of sending and receiving of data to and from an SSH client using the MindTerm implementation. This class can only be loaded when the MindTerm application JAR is on the classpath. Otherwise, a ClassNotFoundException will be thrown.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.foxsmart.ic.net.ProtocolHandler
ProtocolHandler.Protocol
 
Field Summary
static int DEFAULT_SSH_PORT
          The default SSH socket port.
protected  org.apache.commons.logging.Log log
           
protected  MindTermSshConsoleClient ssh1ConsoleClient
           
protected  com.mindbright.ssh2.SSH2ConsoleRemote ssh2ConsoleRemote
           
protected  com.mindbright.ssh2.SSH2SimpleClient ssh2SimpleClient
           
static java.lang.String THREE_DES_CIPHER
          Constant for the 3DES Cipher.
 
Fields inherited from class com.foxsmart.ic.net.AbstractCliProtocolHandler
defaultNoDataReadDelay, defaultProtocolTimeout, PASSWORD_MASK
 
Fields inherited from interface com.foxsmart.ic.net.CliProtocolHandler
CR, DEFAULT_NO_DATA_READ_DELAY, PASSWORD_PROMPT, USERNAME_PROMPT
 
Fields inherited from interface com.foxsmart.ic.net.ProtocolHandler
DEFAULT_PROTOCOL_TIMEOUT_SECONDS
 
Constructor Summary
MindTermSshProtocolHandlerImpl()
          Default Constructor.
 
Method Summary
 void connect(java.lang.String hostname, java.lang.Integer port, java.lang.String username, java.lang.String password, java.lang.Integer timeout)
          Connects to the hostname at the specified port number and authenticates with the remote device.
 void disconnect()
          This method sets the usernameUsed and passwordUsed flags to false.
 boolean getAvailable()
          Returns whether this protocol handler is available.
 java.io.InputStream getInputStream()
          Returns the connection input stream.
static int getMajor(java.lang.String sshVersion)
          Gets the major portion of the SSH version.
static int getMinor(java.lang.String sshVersion)
          Gets the minor portion of the SSH version.
 java.io.OutputStream getOutputStream()
          Returns the connection output stream.
 ProtocolHandler.Protocol getProtocol()
          Returns the SSH protocol.
 int getSshProtocolVersion()
          Gets the currently connected SSH protocol version.
static java.lang.String getSshVersion(java.lang.String hostname, java.lang.Integer port, java.lang.Integer timeout)
          Gets the SSH version string.
 boolean isConnected()
          Returns true if the client is currently connected to a server.
 
Methods inherited from class com.foxsmart.ic.net.AbstractCliProtocolHandler
expect, expect, expect, expect, expect, expect, getAscii, getDefaultNoDataReadDelay, getDefaultProtocolTimeout, getPasswordUsed, getUsernameUsed, read, read, sendCommand, sendCommand, setDefaultNoDataReadDelay, setDefaultProtocolTimeout, setPasswordUsed, setUsernameUsed, toString, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected org.apache.commons.logging.Log log

DEFAULT_SSH_PORT

public static final int DEFAULT_SSH_PORT
The default SSH socket port.

See Also:
Constant Field Values

THREE_DES_CIPHER

public static final java.lang.String THREE_DES_CIPHER
Constant for the 3DES Cipher.

See Also:
Constant Field Values

ssh1ConsoleClient

protected MindTermSshConsoleClient ssh1ConsoleClient

ssh2SimpleClient

protected com.mindbright.ssh2.SSH2SimpleClient ssh2SimpleClient

ssh2ConsoleRemote

protected com.mindbright.ssh2.SSH2ConsoleRemote ssh2ConsoleRemote
Constructor Detail

MindTermSshProtocolHandlerImpl

public MindTermSshProtocolHandlerImpl()
Default Constructor.

Method Detail

getProtocol

public ProtocolHandler.Protocol getProtocol()
Returns the SSH protocol.

Returns:
the SSH protocol.

getAvailable

public boolean getAvailable()
Returns whether this protocol handler is available.

Specified by:
getAvailable in interface ProtocolHandler
Overrides:
getAvailable in class AbstractCliProtocolHandler
Returns:
true when the MindTerm implementation is available in the classpath or false if not.

connect

public void connect(java.lang.String hostname,
                    java.lang.Integer port,
                    java.lang.String username,
                    java.lang.String password,
                    java.lang.Integer timeout)
             throws java.lang.Exception
Description copied from interface: CliProtocolHandler
Connects to the hostname at the specified port number and authenticates with the remote device. A socket connection will be established when this call is complete.

Parameters:
hostname - The name of the remote host.
port - The port to connect to on the remote host. If null is passed in, a default port will be used.
username - The username to connect with. Null should be passed in if no username is required.
password - The password to connect with. Null should be passed in if no password is required.
timeout - The timeout in seconds. If null is passed in, a default timeout will be used.
Throws:
AuthenticationFailedException - when a successful connection could not be made
java.net.SocketException - if the socket timeout could not be set.
java.io.IOException - if the socket could not be opened. In most cases you will only want to catch IOException since SocketException is derived from it.
ThreadTimeoutException - if a timeout occurred while connecting to the router.
java.net.UnknownHostException - If the hostname cannot be resolved.
java.lang.Exception - if any other problems were encountered.
See Also:
CliProtocolHandler.connect(String, Integer, String, String, Integer)

isConnected

public boolean isConnected()
Returns true if the client is currently connected to a server.

Returns:
True if the client is currently connected to a server, false otherwise.

disconnect

public void disconnect()
                throws java.io.IOException
Description copied from class: AbstractCliProtocolHandler
This method sets the usernameUsed and passwordUsed flags to false. Specific handlers should override this method to perform the actual disconnection implementation and call this super method as well.

Specified by:
disconnect in interface CliProtocolHandler
Overrides:
disconnect in class AbstractCliProtocolHandler
Throws:
java.io.IOException - If there is an error closing the socket.
See Also:
CliProtocolHandler.disconnect().

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: CliProtocolHandler
Returns the connection input stream. You should not close the stream when you finish with it. Rather, you should call disconnect.

Returns:
The connection input stream.
See Also:
CliProtocolHandler.getInputStream()

getOutputStream

public java.io.OutputStream getOutputStream()
Description copied from interface: CliProtocolHandler
Returns the connection output stream. You should not close the stream when you finish with it. Rather, you should call disconnect.

Returns:
the connection output stream.
See Also:
CliProtocolHandler.getOutputStream()

getSshProtocolVersion

public int getSshProtocolVersion()
Gets the currently connected SSH protocol version.

Returns:
1 if SSH1 is being used, 2 if SSH2 is being used, or 0 of no connection is established.

getSshVersion

public static java.lang.String getSshVersion(java.lang.String hostname,
                                             java.lang.Integer port,
                                             java.lang.Integer timeout)
                                      throws java.io.IOException
Gets the SSH version string. The getMajor and getMinor methods can be used to parse the string and return the major and minor parts of the version string.

Parameters:
hostname - the hostname to connect to.
port - the port to connect to.
timeout - the socket timeout.
Returns:
the version string.
Throws:
java.io.IOException - if any problems were encountered.

getMajor

public static int getMajor(java.lang.String sshVersion)
                    throws java.lang.Exception
Gets the major portion of the SSH version.

Parameters:
sshVersion - the SSH version.
Returns:
the major portion of the SSH version.
Throws:
java.lang.Exception - if the SSH version isn't valid.

getMinor

public static int getMinor(java.lang.String sshVersion)
                    throws java.lang.Exception
Gets the minor portion of the SSH version.

Parameters:
sshVersion - the SSH version.
Returns:
the minor portion of the SSH version.
Throws:
java.lang.Exception - if the SSH version isn't valid.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.