public class

SshConnector

extends Object
implements MuleContextAware
java.lang.Object
   ↳ org.mule.modules.ssh.multiplexer.SshConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Cloud Connector for ssh that is capable to handle multiple session from different users and reusing the session of any given user if he wants to send multiple messages. Notice that while this connector can handle N sessions for N users, each user can only have 1 active session at a time

Summary

Constants
String SSH_CALLBACK_USER
Fields
private Flow callbackFlow The flow that will receive callback invocations
private String callbackFlowName If not null, a flow with this name will be fetched from the registry and invoked everytime data is received from the other end.
private OutputStream callbackStream
private SSHClient client SSH Client class
private static final Logger logger
private MuleContext muleContext
private Integer receiverBufferSize The size of the receiver buffer in bytes.
private Session session the SSH session
private Session.Shell shell
private boolean shellMode if true, the connection will be opened in shell mode, meaning that the session context will be maintained from the moment it's stablished until it's closed.
private Integer timeout message timeout
private String username The username of the active user
private OutputStream writerStream The stream from wich we write
Public Constructors
SshConnector()
Public Methods
void connect(String username, String password, String host, Integer port)
Starts a connection
void disconnect()
Releases the connection
String getCallbackFlowName()
String getConnectionIdentifier()
Integer getReceiverBufferSize()
Integer getTimeout()
void init()
boolean isConnected()
Returns true if the connection is active
boolean isShellMode()
void send(String content, boolean breakLine)
Sends the provided content to the SSH host.
void setCallbackFlowName(String callbackFlowName)
void setMuleContext(MuleContext context)
void setReceiverBufferSize(Integer receiverBufferSize)
void setShellMode(boolean shellMode)
void setTimeout(Integer timeout)
Protected Methods
void doCallback(String response)
sends the message to the responseFlow if not null
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.mule.api.context.MuleContextAware

Constants

private static final String SSH_CALLBACK_USER

Constant Value: "SSH_CALLBACK_USER"

Fields

private Flow callbackFlow

The flow that will receive callback invocations

private String callbackFlowName

If not null, a flow with this name will be fetched from the registry and invoked everytime data is received from the other end. Keep in mind that SSH is a full duplex protocol, meaning that you can receive data at any time, not just as a reply to a message you have sent.

private OutputStream callbackStream

private SSHClient client

SSH Client class

private static final Logger logger

private MuleContext muleContext

private Integer receiverBufferSize

The size of the receiver buffer in bytes. Defaults to 8192 and must be greater or equal to 1

private Session session

the SSH session

private Session.Shell shell

private boolean shellMode

if true, the connection will be opened in shell mode, meaning that the session context will be maintained from the moment it's stablished until it's closed. If false, then only single commands will be allowed and no context will be passed from one invocation to the next.

private Integer timeout

message timeout

private String username

The username of the active user

private OutputStream writerStream

The stream from wich we write

Public Constructors

public SshConnector ()

Public Methods

public void connect (String username, String password, String host, Integer port)

Starts a connection

Parameters
username The username for the login
password The password for the login
host The address for the target host
port TCP port number in which the host is listening
Throws
ConnectionException if an error occurs connecting

public void disconnect ()

Releases the connection

public String getCallbackFlowName ()

Returns
  • the callbackFlowName

public String getConnectionIdentifier ()

Returns
  • the username of the current connection

public Integer getReceiverBufferSize ()

public Integer getTimeout ()

public void init ()

public boolean isConnected ()

Returns true if the connection is active

public boolean isShellMode ()

Returns
  • the shellMode

public void send (String content, boolean breakLine)

Sends the provided content to the SSH host. When the response is received, a new mule message will be generated and will be sent to the configured callback flow. That message will carry the response on the payload and will also include an inbound property called SSH_CALLBACK_USER that specifies the name of the user for whom the resopnse was sent.

Parameters
content The content to send
breakLine If true, then a new line character is added at the end of the conent
Throws
IOException is there was an error in the line

public void setCallbackFlowName (String callbackFlowName)

Parameters
callbackFlowName

public void setMuleContext (MuleContext context)

Parameters
context

public void setReceiverBufferSize (Integer receiverBufferSize)

Parameters
receiverBufferSize

public void setShellMode (boolean shellMode)

Parameters
shellMode

public void setTimeout (Integer timeout)

Parameters
timeout

Protected Methods

protected void doCallback (String response)

sends the message to the responseFlow if not null

Parameters
response