com.sshtools.j2ssh.connection
Class ConnectionProtocol

java.lang.Object
  |
  +--com.sshtools.j2ssh.transport.Service
        |
        +--com.sshtools.j2ssh.connection.ConnectionProtocol
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
SessionClient

public abstract class ConnectionProtocol
extends Service

Implementation for the SSH connection protocol as a transport layer service. This class provides method for sending all the available connection protocol message as well as abstract methods for handling the same messages.

Version:
1.0
Author:
Lee David Painter ( lee@sshtools.com )

Constructor Summary
ConnectionProtocol()
          Constructor for the SshConnectionProtocol object
 
Method Summary
protected  void closeChannel(Channel channel)
           Closes the channel by sending the SSH_MSG_CHANNEL_CLOSE message.
protected abstract  void onChannelClose(Channel channel)
           Implement this method to handle the SSH_MSG_CHANNEL_CLOSE message.
protected abstract  void onChannelData(Channel channel, byte[] data)
           Implement this method to handle the SSH_MSG_CHANNEL_DATA message.
protected abstract  void onChannelEOF(Channel channel)
           Implement this method to handle the SSH_MSG_CHANNEL_EOF message.
protected abstract  void onChannelExtData(Channel channel, byte[] data)
           Implement this methos to handle the SSH_MSG_CHANNEL_EXT_DATA message.
protected abstract  boolean onChannelOpen(Channel channel, byte[] channelData)
           Implements this method to handle the SSH_MSG_CHANNEL_OPEN message.
protected abstract  void onChannelRequest(Channel channel, java.lang.String requestType, boolean wantReply, byte[] requestData)
           Implement this method to handle the SSH_MSG_CHANNEL_REQUEST message.
protected abstract  void onGlobalRequest(java.lang.String requestName, boolean wantReply, byte[] requestData)
           Implement this method to handle the SSH_MSG_GLOBAL_REQUEST message.
protected abstract  void onGlobalRequestFailure()
           Implements this method to handle the SSH_MSG_REQUEST_FAILURE message.
protected abstract  void onGlobalRequestSuccess(byte[] requestData)
           Implement this method to handle the SSH_MSG_REQUEST_SUCCESS message.
 void onMessageReceived(SshMessage msg)
           Implements the abstract method to handle the registered message notifications.
 void onServiceInit()
           Called by the framework once the service has been accepted or requested.
protected  Channel openChannel(java.lang.String channelName, java.lang.String channelType, long initialWindowSize, long maximumPacketSize, byte[] channelData)
           Syncrhonously opens a channel by sending the SSH_MSG_CHANNEL_OPEN message and waits for either the SSH_MSG_CHANNEL_OPEN_FAILURE or SSH_MSG_CHANNEL_OPEN_CONFIRMATION messages.
protected  void sendChannelData(Channel channel, byte[] data)
           Sends data to the channel using the SSH_MSG_CHANNEL_DATA.
protected  void sendChannelEOF(Channel channel)
           Sets the local channel as End Of File by sending the SSH_MSG_CHANNEL_EOF message.
protected  void sendChannelExtData(Channel channel, byte[] data)
           Sends data to the channel using the SSH_MSG_CHANNEL_EXT_DATA.
protected  void sendChannelFailure(Channel channel)
           Sends the SSH_MSG_CHANNEL_FAILURE message.
protected  void sendChannelOpenConfirmation(Channel channel, byte[] channelData)
           Sends the SSH_MSG_CHANNEL_OPEN_CONFIRMATION message.
protected  void sendChannelOpenFailure(Channel channel, long reasonCode, java.lang.String additionalInfo, java.lang.String languageTag)
           Sends the SSH_MSG_CHANNEL_OPEN_FAILURE message.
protected  boolean sendChannelRequest(Channel channel, java.lang.String requestType, boolean wantReply, byte[] requestData)
           Sends the SSH_MSG_CHANNEL_REQUEST message.
protected  void sendChannelSuccess(Channel channel)
           Sends the SSH_MSG_CHANNEL_SUCCES message.
protected  void sendChannelWindowAdjust(Channel channel, long bytesToAdd)
           Sends the SSH_MSG_CHANNEL_WINDOW_ADJUST message.
protected  void sendGlobalRequest(java.lang.String requestName, boolean wantReply, byte[] requestData)
           Sends the connection protocol message SSH_MSG_GLOBAL_REQUEST.
protected  void sendGlobalRequestFailure()
           Sends the connection protocol message SSH_MSG_REQUEST_FAILURE.
protected  void sendGlobalRequestSuccess(byte[] requestData)
           Sends the connection protocol message SSH_MSG_REQUEST_SUCCESS.
 
Methods inherited from class com.sshtools.j2ssh.transport.Service
getExchangeHash, getMessageStore, getServiceName, getTransportLayer, onDisconnect, onServiceAccept, onServiceRequest, onThreadException, run, start, stop, waitForSingleMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionProtocol

public ConnectionProtocol()
Constructor for the SshConnectionProtocol object

Method Detail

onServiceInit

public void onServiceInit()
                   throws ServiceOperationException

Called by the framework once the service has been accepted or requested.

Specified by:
onServiceInit in class Service
Throws:
ServiceOperationException

sendGlobalRequest

protected void sendGlobalRequest(java.lang.String requestName,
                                 boolean wantReply,
                                 byte[] requestData)
                          throws TransportProtocolException

Sends the connection protocol message SSH_MSG_GLOBAL_REQUEST.

Parameters:
requestName - The request name
wantReply - Whether a reply is needed
requestData - The request specific data
Throws:
TransportProtocolException

sendGlobalRequestSuccess

protected void sendGlobalRequestSuccess(byte[] requestData)
                                 throws TransportProtocolException

Sends the connection protocol message SSH_MSG_REQUEST_SUCCESS.

Parameters:
requestData - The request specific data
Throws:
TransportProtocolException

sendGlobalRequestFailure

protected void sendGlobalRequestFailure()
                                 throws TransportProtocolException

Sends the connection protocol message SSH_MSG_REQUEST_FAILURE.

Throws:
TransportProtocolException

openChannel

protected Channel openChannel(java.lang.String channelName,
                              java.lang.String channelType,
                              long initialWindowSize,
                              long maximumPacketSize,
                              byte[] channelData)
                       throws TransportProtocolException,
                              ServiceOperationException

Syncrhonously opens a channel by sending the SSH_MSG_CHANNEL_OPEN message and waits for either the SSH_MSG_CHANNEL_OPEN_FAILURE or SSH_MSG_CHANNEL_OPEN_CONFIRMATION messages. If the request succeeds the Channel instance os returned, otherwise the method returns null.

Parameters:
channelName - The descriptive name for the channel
channelType - The SSH channel type (i.e. ;session')
initialWindowSize - The initial window size required
maximumPacketSize - The maximum packet size required
channelData - Channel specific request data
Returns:
Description of the Return Value
Throws:
TransportProtocolException
ServiceOperationException - Description of the Exception

sendChannelOpenConfirmation

protected void sendChannelOpenConfirmation(Channel channel,
                                           byte[] channelData)
                                    throws TransportProtocolException

Sends the SSH_MSG_CHANNEL_OPEN_CONFIRMATION message.

Parameters:
channel - The channel to confirm open
channelData - Channel specific data
Throws:
TransportProtocolException

sendChannelOpenFailure

protected void sendChannelOpenFailure(Channel channel,
                                      long reasonCode,
                                      java.lang.String additionalInfo,
                                      java.lang.String languageTag)
                               throws TransportProtocolException

Sends the SSH_MSG_CHANNEL_OPEN_FAILURE message.

Parameters:
channel - The channel to inform of failure
reasonCode - The reason code
additionalInfo - Additional information
languageTag - The language tag
Throws:
TransportProtocolException

closeChannel

protected void closeChannel(Channel channel)
                     throws TransportProtocolException

Closes the channel by sending the SSH_MSG_CHANNEL_CLOSE message.

Parameters:
channel - The channel to close
Throws:
TransportProtocolException

sendChannelEOF

protected void sendChannelEOF(Channel channel)
                       throws TransportProtocolException

Sets the local channel as End Of File by sending the SSH_MSG_CHANNEL_EOF message.

Parameters:
channel - The channel to set EOF
Throws:
TransportProtocolException

sendChannelData

protected void sendChannelData(Channel channel,
                               byte[] data)
                        throws WindowSpaceNotAvailableException,
                               TransportProtocolException

Sends data to the channel using the SSH_MSG_CHANNEL_DATA.

Parameters:
channel - The channel to send data over
data - The data to send
Throws:
TransportProtocolException
WindowSpaceNotAvailableException - Description of the Exception

sendChannelExtData

protected void sendChannelExtData(Channel channel,
                                  byte[] data)
                           throws WindowSpaceNotAvailableException,
                                  TransportProtocolException

Sends data to the channel using the SSH_MSG_CHANNEL_EXT_DATA.

Parameters:
channel - The channel to send data through
data - The data channel
Throws:
TransportProtocolException
WindowSpaceNotAvailableException - Description of the Exception

sendChannelFailure

protected void sendChannelFailure(Channel channel)
                           throws TransportProtocolException

Sends the SSH_MSG_CHANNEL_FAILURE message.

Parameters:
channel - The failed channel
Throws:
TransportProtocolException

sendChannelWindowAdjust

protected void sendChannelWindowAdjust(Channel channel,
                                       long bytesToAdd)
                                throws TransportProtocolException

Sends the SSH_MSG_CHANNEL_WINDOW_ADJUST message.

Parameters:
channel - The channel to send
bytesToAdd - The number of bytes to add to the window space
Throws:
TransportProtocolException

sendChannelSuccess

protected void sendChannelSuccess(Channel channel)
                           throws TransportProtocolException

Sends the SSH_MSG_CHANNEL_SUCCES message.

Parameters:
channel - The channel
Throws:
TransportProtocolException

sendChannelRequest

protected boolean sendChannelRequest(Channel channel,
                                     java.lang.String requestType,
                                     boolean wantReply,
                                     byte[] requestData)
                              throws TransportProtocolException,
                                     ServiceOperationException

Sends the SSH_MSG_CHANNEL_REQUEST message.

Parameters:
channel - The channel for the request
requestType - The channel request type
wantReply - Whether a reply is needed
requestData - The request specific data
Returns:
Description of the Return Value
Throws:
TransportProtocolException
ServiceOperationException - Description of the Exception

onMessageReceived

public void onMessageReceived(SshMessage msg)
                       throws ServiceOperationException,
                              TransportProtocolException

Implements the abstract method to handle the registered message notifications.

Specified by:
onMessageReceived in class Service
Parameters:
msg - The message received
Throws:
ServiceOperationException
TransportProtocolException

onGlobalRequest

protected abstract void onGlobalRequest(java.lang.String requestName,
                                        boolean wantReply,
                                        byte[] requestData)
                                 throws ServiceOperationException

Implement this method to handle the SSH_MSG_GLOBAL_REQUEST message.

Parameters:
requestName - The name of the request
wantReply - True is the remote computer wants a reply. Use sendGlobalRequestSuccess or sendGlobalRequestFailure
requestData - Request specific data
Throws:
ServiceOperationException - Throw for any exceptions

onGlobalRequestSuccess

protected abstract void onGlobalRequestSuccess(byte[] requestData)
                                        throws ServiceOperationException

Implement this method to handle the SSH_MSG_REQUEST_SUCCESS message.

Parameters:
requestData - Request specific data
Throws:
ServiceOperationException - Throw for any exceptions

onGlobalRequestFailure

protected abstract void onGlobalRequestFailure()
                                        throws ServiceOperationException

Implements this method to handle the SSH_MSG_REQUEST_FAILURE message.

Throws:
ServiceOperationException - Throw for any exceptions

onChannelOpen

protected abstract boolean onChannelOpen(Channel channel,
                                         byte[] channelData)
                                  throws ServiceOperationException

Implements this method to handle the SSH_MSG_CHANNEL_OPEN message. Use sendChannelOpenConfirmation or sendChannelOpenFailure methods to respond.

Parameters:
channel - The channel to be opened
channelData - Channel specific data
Returns:
Return true if channel has been opened
Throws:
ServiceOperationException - Throw for any exceptions

onChannelClose

protected abstract void onChannelClose(Channel channel)
                                throws ServiceOperationException

Implement this method to handle the SSH_MSG_CHANNEL_CLOSE message.

Parameters:
channel - The channel being closed
Throws:
ServiceOperationException - Throw for any exceptions

onChannelEOF

protected abstract void onChannelEOF(Channel channel)
                              throws ServiceOperationException

Implement this method to handle the SSH_MSG_CHANNEL_EOF message.

Parameters:
channel - The channel being set to EOF
Throws:
ServiceOperationException - Throw for any exceptions

onChannelRequest

protected abstract void onChannelRequest(Channel channel,
                                         java.lang.String requestType,
                                         boolean wantReply,
                                         byte[] requestData)
                                  throws ServiceOperationException

Implement this method to handle the SSH_MSG_CHANNEL_REQUEST message.

Parameters:
channel - The channel for the request
requestType - The request type
wantReply - true if the remote side requires a reply Use sendChannelRequestSuccess or sendChannelRequestFailure
requestData - The request specific data
Throws:
ServiceOperationException - Throw for any exceptions

onChannelData

protected abstract void onChannelData(Channel channel,
                                      byte[] data)
                               throws ServiceOperationException

Implement this method to handle the SSH_MSG_CHANNEL_DATA message.

Parameters:
channel - The data's channel
data - The data
Throws:
ServiceOperationException - Throw for ant exceptions

onChannelExtData

protected abstract void onChannelExtData(Channel channel,
                                         byte[] data)
                                  throws ServiceOperationException

Implement this methos to handle the SSH_MSG_CHANNEL_EXT_DATA message.

Parameters:
channel - The data's channel
data - The data
Throws:
ServiceOperationException - Throw for any exceptions


Copyright © 2002 Sshtools.com. All Rights Reserved.