Class WindowsSession
java.lang.Object
com.oracle.bedrock.runtime.remote.windows.winrm.WindowsSession
- All Implemented Interfaces:
Closeable,AutoCloseable
This class represents a reference to a WinRS remote
shell.
Copyright (c) 2015. All Rights Reserved. Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
- Author:
- Jonathan Knight
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe action name for the WinRM Command actionstatic final StringThe action name for the WS-Man Create actionstatic final StringThe action name for the WinRM Delete actionstatic final StringThe action name for the WinRM Receive actionstatic final StringThe action name for the WinRM Send actionstatic final StringThe action name for the WinRM Signal actionstatic final intThe default port that WinRM listens onstatic final StringThe action name for the WinRM terminate signalstatic final StringThe reply-to URI used in the SOAP envelopestatic final StringThe WinRM resource URI used in the SOAP envelopestatic final StringThe default WinRM url suffix -
Constructor Summary
ConstructorsConstructorDescriptionWindowsSession(SoapConnection connection, com.oracle.bedrock.Option... options) Create a newWindowsSessionthat connects to the WinRM service on the specified host.WindowsSession(String hostName, int port, String userName, Authentication authentication, com.oracle.bedrock.Option... options) Create a newWindowsSessionthat connects to the WinRM service on the specified host. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close thisWindowsSession.protected voidconnect()Connect thisWindowsSessionto the remote Windows platform.protected voidConnect thisWindowsSessionto the remote Windows platform.protected voidconnect(String workingDirectory, Properties environment) Connect thisWindowsSessionto the remote Windows platform.protected org.w3c.soap.envelope.EnvelopecreateEnvelope(String action) protected InputStreamConnectorprotected OutputStreamConnectorcreateOutputStreamConnector(OutputStream stdOut, OutputStream stdErr) voidexecute(String command, List<String> args, InputStream stdIn, OutputStream stdOut, OutputStream stdErr) Execute the specified command in the current Shell.intObtain the exit code from the last executed command.protected <T> TfindFirst(Collection<?> collection, Class<T> type) Obtain the ID of the currently executing command.protected InputStreamConnectorObtain theInputStreamConnectorthat connects the current command stdin stream.protected OutputStreamConnectorObtain the ID of the WinRM shell being used by this session.Obtain theSoapConnectionbeing used by thisWindowsSessionto send SOAP messages.protected com.microsoft.wsman.shell.ReceiveResponseRead the output from the current commands stdout and stderr streams.protected voidsetCommandId(String commandId) Set the ID of the currently executing command.protected voidsetInputStreamConnector(InputStreamConnector inputStreamConnector) Set theInputStreamConnectorthat connects the current command stdin stream.protected voidsetOutputStreamConnector(OutputStreamConnector outputStreamConnector) protected voidSet the reference ID of the currently connected WinRM Shell.protected voidintwaitFor(com.oracle.bedrock.Option... options) Wait for the currently executing command to terminate and return its exit value.protected voidwriteToInputStream(String message)
-
Field Details
-
ACTION_CREATE
The action name for the WS-Man Create action- See Also:
-
ACTION_COMMAND
The action name for the WinRM Command action- See Also:
-
ACTION_RECEIVE
The action name for the WinRM Receive action- See Also:
-
ACTION_SIGNAL
The action name for the WinRM Signal action- See Also:
-
ACTION_DELETE
The action name for the WinRM Delete action- See Also:
-
ACTION_SEND
The action name for the WinRM Send action- See Also:
-
SIGNAL_TERM
The action name for the WinRM terminate signal- See Also:
-
URI_WINRM_RESOURCE
The WinRM resource URI used in the SOAP envelope- See Also:
-
URI_REPLY_TO
The reply-to URI used in the SOAP envelope- See Also:
-
DEFAULT_WINRM_PORT
public static final int DEFAULT_WINRM_PORTThe default port that WinRM listens on- See Also:
-
WSMAN_PATH
The default WinRM url suffix- See Also:
-
-
Constructor Details
-
WindowsSession
Create a newWindowsSessionthat connects to the WinRM service on the specified host.- Parameters:
connection- theSoapConnectionto use to send SOAP messagesoptions- theOptions controlling the session
-
WindowsSession
public WindowsSession(String hostName, int port, String userName, Authentication authentication, com.oracle.bedrock.Option... options) Create a newWindowsSessionthat connects to the WinRM service on the specified host.- Parameters:
hostName- the host name of the host running the WinRM serviceport- the port that the WinRM service is listening onuserName- the name of the user to use to connect to the WinRM serviceauthentication- the authentication to use to connect to the WinRMoptions- theOptions controlling the session
-
-
Method Details
-
getSoapConnection
Obtain theSoapConnectionbeing used by thisWindowsSessionto send SOAP messages.- Returns:
- the
SoapConnectionbeing used by thisWindowsSessionto send SOAP messages
-
getShellReferenceId
Obtain the ID of the WinRM shell being used by this session.- Returns:
- the ID of the WinRM shell being used by this session
-
setShellReferenceId
Set the reference ID of the currently connected WinRM Shell.- Parameters:
id- the reference ID of the currently connected WinRM Shell
-
getCommandId
Obtain the ID of the currently executing command.- Returns:
- the ID of the currently executing command
-
setCommandId
Set the ID of the currently executing command.- Parameters:
commandId- the ID of the currently executing command
-
getInputStreamConnector
Obtain theInputStreamConnectorthat connects the current command stdin stream.- Returns:
- the
InputStreamConnectorthat connects the current command stdin stream
-
setInputStreamConnector
Set theInputStreamConnectorthat connects the current command stdin stream.- Parameters:
inputStreamConnector- theInputStreamConnectorthat connects the current command stdin stream
-
getOutputStreamConnector
-
setOutputStreamConnector
-
close
public void close()Close thisWindowsSession.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
connect
Connect thisWindowsSessionto the remote Windows platform. The working directory will be the users home directory.- Throws:
Exception- if the connection fails
-
connect
Connect thisWindowsSessionto the remote Windows platform. The working directory will be the specified directory.- Parameters:
workingDirectory- the working directory for this session- Throws:
Exception- if the connection fails
-
connect
Connect thisWindowsSessionto the remote Windows platform. The working directory will be the specified directory.- Parameters:
workingDirectory- the working directory for this sessionenvironment- the environment variables to set for the session- Throws:
IOException- if the connection failsIllegalStateException- if this session is already connected
-
execute
public void execute(String command, List<String> args, InputStream stdIn, OutputStream stdOut, OutputStream stdErr) throws IOException Execute the specified command in the current Shell.- Parameters:
command- the command to executeargs- the command line arguments for the commandstdIn- theInputStreamto use as the commands stdinstdOut- theOutputStreamto use as the commands stdoutstdErr- theOutputStreamto use as the commands stderr- Throws:
IOException- if an error occurs executing the command
-
createOutputStreamConnector
protected OutputStreamConnector createOutputStreamConnector(OutputStream stdOut, OutputStream stdErr) -
createInputStreamConnector
-
terminateCommand
- Throws:
IOException
-
readOutputStreams
Read the output from the current commands stdout and stderr streams.- Returns:
- the
ReceiveResponsecontaining the stdout and stderr streams - Throws:
IOException- if an error occurs
-
writeToInputStream
- Throws:
IOException
-
createEnvelope
- Throws:
IOException
-
findFirst
-
exitValue
public int exitValue()Obtain the exit code from the last executed command.- Returns:
- the exit code from the last executed command or -1 if no command has been executed
-
waitFor
public int waitFor(com.oracle.bedrock.Option... options) Wait for the currently executing command to terminate and return its exit value.- Parameters:
options- theOptions for waiting, includingTimeout- Returns:
- the exit value from the currently executing command
-