|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.foxsmart.ic.net.MindTermSshProtocolHandler
public class MindTermSshProtocolHandler
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 is a wrapper to the MindTermSshProtocolHandlerImpl class which contains the implementation. The implementation is separated out to ensure the getAvailable method can be implemented without the mindterm.jar implementation being on the classpath. Otherwise, a NoClassDefFoundError exception will be thrown when instantiating this handler (i.e. the exception will get thrown before the handler can determine if the implementation is available or not).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.foxsmart.ic.net.ProtocolHandler |
|---|
ProtocolHandler.Protocol |
| Field Summary | |
|---|---|
protected org.apache.commons.logging.Log |
log
|
| 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 | |
|---|---|
MindTermSshProtocolHandler()
Default Constructor. |
|
| Method Summary | |
|---|---|
protected void |
checkForValidHandler()
|
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()
Disconnects the socket connection. |
java.lang.String |
expect(java.util.List matches)
Reads data from the device until one of the expected strings is found. |
java.lang.String |
expect(java.util.List matches,
boolean includeMatch)
Reads data from the device until one of the expected strings is found. |
java.lang.String |
expect(java.util.List matches,
boolean includeMatch,
java.lang.Integer timeout)
Reads data from the device until one of a list of expected strings is found. |
java.lang.String |
expect(java.lang.String match)
Reads data from the device until the expected string is found. |
java.lang.String |
expect(java.lang.String match,
boolean includeMatch)
Reads data from the device until the expected string is found. |
java.lang.String |
expect(java.lang.String match,
boolean includeMatch,
java.lang.Integer timeout)
Reads data from the device until the expected string is found. |
java.lang.String |
getAscii(java.lang.String string,
int pos)
Gets a formatted ASCII dump of the passed in string. |
boolean |
getAvailable()
Returns whether this protocol handler is available. |
int |
getDefaultNoDataReadDelay()
Gets the default no data read delay. |
java.lang.Integer |
getDefaultProtocolTimeout()
Gets the default operation timeout value. |
java.io.InputStream |
getInputStream()
Returns the connection input stream. |
java.io.OutputStream |
getOutputStream()
Returns the connection output stream. |
boolean |
getPasswordUsed()
Gets whether the password was used for authentication. |
ProtocolHandler.Protocol |
getProtocol()
Returns the SSH protocol. |
int |
getSshProtocolVersion()
|
boolean |
getUsernameUsed()
Gets whether the username was used for authentication. |
boolean |
isConnected()
Returns true if the client is currently connected to a server. |
java.lang.String |
read()
Reads the next set of data from the device until enough time has passed that we assume no more data will arrive. |
java.lang.String |
read(java.lang.Integer timeout)
Reads the next set of data from the device until enough time has passed that we assume no more data will arrive. |
void |
sendCommand(java.lang.String command)
Sends a command to the device. |
void |
sendCommand(java.lang.String command,
boolean containsPassword)
Sends a command to the device. |
void |
setDefaultNoDataReadDelay(int delay)
Modifies the default no data read delay in 1/10 seconds. |
void |
setDefaultProtocolTimeout(java.lang.Integer timeout)
Modifies the default operation protocol timeout value. |
void |
setPasswordUsed(boolean passwordUsed)
Sets whether the password was used for authentication. |
void |
setUsernameUsed(boolean usernameUsed)
Sets whether the username was used for authentication. |
java.lang.String |
toString()
|
void |
write(java.lang.String text)
Writes the specified string to the device. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected org.apache.commons.logging.Log log
| Constructor Detail |
|---|
public MindTermSshProtocolHandler()
| Method Detail |
|---|
public ProtocolHandler.Protocol getProtocol()
getProtocol in interface ProtocolHandlerpublic boolean getAvailable()
getAvailable in interface ProtocolHandler
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
CliProtocolHandler
connect in interface CliProtocolHandlerhostname - 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.
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.public boolean isConnected()
CliProtocolHandler
isConnected in interface CliProtocolHandler
public void disconnect()
throws java.io.IOException
CliProtocolHandler
disconnect in interface CliProtocolHandlerjava.io.IOException - If there is an error closing the socket.public java.io.InputStream getInputStream()
CliProtocolHandler
getInputStream in interface CliProtocolHandlerpublic java.io.OutputStream getOutputStream()
CliProtocolHandler
getOutputStream in interface CliProtocolHandler
public void write(java.lang.String text)
throws java.io.IOException
CliProtocolHandler
write in interface CliProtocolHandlertext - The text to write to the device.
java.io.IOException - if there was a problem writing the data.
public void sendCommand(java.lang.String command)
throws java.io.IOException
CliProtocolHandler
sendCommand in interface CliProtocolHandlercommand - The command to send to the device.
java.io.IOException - if there was a problem sending the command.
public void sendCommand(java.lang.String command,
boolean containsPassword)
throws java.io.IOException
CliProtocolHandler
sendCommand in interface CliProtocolHandlercommand - The command to send to the device.containsPassword - true if the command contains a password or false if not. Send true to cause the password
to only be logged in "trace" mode.
java.io.IOException - if there was a problem sending the command.
public java.lang.String expect(java.lang.String match,
boolean includeMatch)
throws java.lang.Exception
CliProtocolHandler
expect in interface CliProtocolHandlermatch - The string to search for.includeMatch - If true, the match string is returned in the resulting data string. If false, the match
string is not returned as part of the resultant string.
ThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String expect(java.util.List matches,
boolean includeMatch)
throws java.lang.Exception
CliProtocolHandler
expect in interface CliProtocolHandlermatches - The strings to search for.includeMatch - If true, the match string is returned in the resulting data string. If false, the match
string is not returned as part of the resultant string.
ThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String expect(java.lang.String match)
throws java.lang.Exception
CliProtocolHandler
expect in interface CliProtocolHandlermatch - The string to search for.
ThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String expect(java.util.List matches)
throws java.lang.Exception
CliProtocolHandler
expect in interface CliProtocolHandlermatches - The strings to search for.
ThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String read()
throws java.lang.Exception
CliProtocolHandler
read in interface CliProtocolHandlerThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String expect(java.lang.String match,
boolean includeMatch,
java.lang.Integer timeout)
throws java.lang.Exception
CliProtocolHandler
expect in interface CliProtocolHandlermatch - The string to search for.includeMatch - If true, the match string is returned in the resulting data string. If false, the match
string is not returned as part of the resultant string.timeout - The timeout value in seconds to wait for the data to be returned. If null is passed, no timeout
will be used. Beware that if the expected match string is not found or if the device doesn't respond, this method
will not return.
ThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String expect(java.util.List matches,
boolean includeMatch,
java.lang.Integer timeout)
throws java.lang.Exception
CliProtocolHandler
expect in interface CliProtocolHandlermatches - The strings to search for.includeMatch - If true, the match string is returned in the resulting data string. If false, the match
string is not returned as part of the resultant string.timeout - The timeout value in seconds to wait for the data to be returned. If null is passed, no timeout
will be used. Beware that if the expected match string is not found or if the device doesn't respond, this method
will not return.
ThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String read(java.lang.Integer timeout)
throws java.lang.Exception
CliProtocolHandler
read in interface CliProtocolHandlertimeout - The timeout value in seconds to wait for the data to be returned. If null is passed, no timeout
will be used. Beware that if the expected match string is not found or if the device doesn't respond, this method
will not return.
ThreadTimeoutException - if the expected string was not found within the passed in
timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.
public java.lang.String getAscii(java.lang.String string,
int pos)
CliProtocolHandler
getAscii in interface CliProtocolHandlerstring - the string to logpos - the byte position of the read string
public void setDefaultProtocolTimeout(java.lang.Integer timeout)
ProtocolHandler
setDefaultProtocolTimeout in interface ProtocolHandlertimeout - The default timeout value in seconds to wait for the data to be returned. If null is passed, no
timeout will be used. Beware that if an expected match string is not found or if the device doesn't respond, the
expect method will not return.public java.lang.Integer getDefaultProtocolTimeout()
ProtocolHandler
getDefaultProtocolTimeout in interface ProtocolHandlerpublic void setDefaultNoDataReadDelay(int delay)
CliProtocolHandler
setDefaultNoDataReadDelay in interface CliProtocolHandlerdelay - The default no data read delay.public int getDefaultNoDataReadDelay()
CliProtocolHandler
getDefaultNoDataReadDelay in interface CliProtocolHandlerpublic void setUsernameUsed(boolean usernameUsed)
CliProtocolHandler
setUsernameUsed in interface CliProtocolHandlerusernameUsed - True if the username was used or false if not.public boolean getUsernameUsed()
CliProtocolHandler
getUsernameUsed in interface CliProtocolHandlerpublic void setPasswordUsed(boolean passwordUsed)
CliProtocolHandler
setPasswordUsed in interface CliProtocolHandlerpasswordUsed - True if the password was used or false if not.public boolean getPasswordUsed()
CliProtocolHandler
getPasswordUsed in interface CliProtocolHandlerpublic int getSshProtocolVersion()
protected void checkForValidHandler()
throws java.lang.RuntimeException
java.lang.RuntimeExceptionpublic java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||