Package org.apache.sshd.server.shell
Class ProcessShell
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.server.shell.ProcessShell
-
- All Implemented Interfaces:
SessionContextHolder
,SessionHolder<ServerSession>
,CommandLifecycle
,ServerSessionHolder
,SessionAware
,InvertedShell
public class ProcessShell extends AbstractLoggingBean implements InvertedShell
Bridges the I/O streams between the SSH command and the process that executes it
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelSession
channel
private java.lang.String
cmdValue
private java.util.List<java.lang.String>
command
private TtyFilterInputStream
err
private TtyFilterOutputStream
in
private TtyFilterInputStream
out
private java.lang.Process
process
private ServerSession
session
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description ProcessShell(java.lang.String... command)
ProcessShell(java.util.Collection<java.lang.String> command)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy(ChannelSession channel)
This method is called by the SSH server to destroy the command because the client has disconnected somehow.int
exitValue()
Retrieve the exit value of the shell.ChannelSession
getChannelSession()
java.io.InputStream
getErrorStream()
java.io.OutputStream
getInputStream()
Returns the output stream used to feed the shell.java.io.InputStream
getOutputStream()
ServerSession
getServerSession()
boolean
isAlive()
Check if the underlying shell is still aliveprotected java.util.Map<java.lang.String,java.lang.String>
resolveShellEnvironment(java.util.Map<java.lang.String,java.lang.String> env)
protected java.util.Map<PtyMode,java.lang.Integer>
resolveShellTtyOptions(java.util.Map<PtyMode,java.lang.Integer> modes)
void
setSession(ServerSession session)
void
start(ChannelSession channel, Environment env)
Starts the command execution.java.lang.String
toString()
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.server.shell.InvertedShell
getSession
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
-
-
-
Field Detail
-
command
private final java.util.List<java.lang.String> command
-
cmdValue
private java.lang.String cmdValue
-
session
private ServerSession session
-
channel
private ChannelSession channel
-
process
private java.lang.Process process
-
in
private TtyFilterOutputStream in
-
out
private TtyFilterInputStream out
-
err
private TtyFilterInputStream err
-
-
Constructor Detail
-
ProcessShell
public ProcessShell(java.lang.String... command)
- Parameters:
command
- The command components which when joined (with space separator) create the full command to be executed by the shell
-
ProcessShell
public ProcessShell(java.util.Collection<java.lang.String> command)
-
-
Method Detail
-
getServerSession
public ServerSession getServerSession()
- Specified by:
getServerSession
in interfaceServerSessionHolder
- Returns:
- The underlying
ServerSession
used
-
setSession
public void setSession(ServerSession session)
- Specified by:
setSession
in interfaceSessionAware
- Parameters:
session
- TheServerSession
in which this shell will be executed.
-
getChannelSession
public ChannelSession getChannelSession()
- Specified by:
getChannelSession
in interfaceInvertedShell
- Returns:
- The
ChannelSession
instance through which the shell was created - may benull
if shell not started yet
-
start
public void start(ChannelSession channel, Environment env) throws java.io.IOException
Description copied from interface:CommandLifecycle
Starts the command execution. All streams must have been set before calling this method. The command should implementRunnable
, and this method should spawn a new thread like:Thread(this).start();
- Specified by:
start
in interfaceCommandLifecycle
- Parameters:
channel
- TheChannelSession
through which the command has been receivedenv
- TheEnvironment
- Throws:
java.io.IOException
- If failed to start
-
resolveShellEnvironment
protected java.util.Map<java.lang.String,java.lang.String> resolveShellEnvironment(java.util.Map<java.lang.String,java.lang.String> env)
-
resolveShellTtyOptions
protected java.util.Map<PtyMode,java.lang.Integer> resolveShellTtyOptions(java.util.Map<PtyMode,java.lang.Integer> modes)
-
getInputStream
public java.io.OutputStream getInputStream()
Description copied from interface:InvertedShell
Returns the output stream used to feed the shell. This method is called after the shell has been started.- Specified by:
getInputStream
in interfaceInvertedShell
- Returns:
- The
OutputStream
used to feed the shell
-
getOutputStream
public java.io.InputStream getOutputStream()
- Specified by:
getOutputStream
in interfaceInvertedShell
- Returns:
- The
InputStream
representing the output stream of the shell
-
getErrorStream
public java.io.InputStream getErrorStream()
- Specified by:
getErrorStream
in interfaceInvertedShell
- Returns:
- The
InputStream
representing the error stream of the shell
-
isAlive
public boolean isAlive()
Description copied from interface:InvertedShell
Check if the underlying shell is still alive- Specified by:
isAlive
in interfaceInvertedShell
- Returns:
true
if alive
-
exitValue
public int exitValue()
Description copied from interface:InvertedShell
Retrieve the exit value of the shell. This method must only be called when the shell is not alive anymore.- Specified by:
exitValue
in interfaceInvertedShell
- Returns:
- the exit value of the shell
-
destroy
public void destroy(ChannelSession channel)
Description copied from interface:CommandLifecycle
This method is called by the SSH server to destroy the command because the client has disconnected somehow.- Specified by:
destroy
in interfaceCommandLifecycle
- Parameters:
channel
- TheChannelSession
through which the command has been received
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-