Class WindowsSession

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class WindowsSession
    extends Object
    implements Closeable
    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
    • Constructor Detail

      • WindowsSession

        public WindowsSession​(SoapConnection connection,
                              com.oracle.bedrock.Option... options)
        Create a new WindowsSession that connects to the WinRM service on the specified host.
        Parameters:
        connection - the SoapConnection to use to send SOAP messages
        options - the Options controlling the session
      • WindowsSession

        public WindowsSession​(String hostName,
                              int port,
                              String userName,
                              Authentication authentication,
                              com.oracle.bedrock.Option... options)
        Create a new WindowsSession that connects to the WinRM service on the specified host.
        Parameters:
        hostName - the host name of the host running the WinRM service
        port - the port that the WinRM service is listening on
        userName - the name of the user to use to connect to the WinRM service
        authentication - the authentication to use to connect to the WinRM
        options - the Options controlling the session
    • Method Detail

      • getShellReferenceId

        public String 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

        protected void setShellReferenceId​(String id)
        Set the reference ID of the currently connected WinRM Shell.
        Parameters:
        id - the reference ID of the currently connected WinRM Shell
      • getCommandId

        public String getCommandId()
        Obtain the ID of the currently executing command.
        Returns:
        the ID of the currently executing command
      • setCommandId

        protected void setCommandId​(String commandId)
        Set the ID of the currently executing command.
        Parameters:
        commandId - the ID of the currently executing command
      • setOutputStreamConnector

        protected void setOutputStreamConnector​(OutputStreamConnector outputStreamConnector)
      • connect

        protected void connect()
                        throws Exception
        Connect this WindowsSession to the remote Windows platform. The working directory will be the users home directory.
        Throws:
        Exception - if the connection fails
      • connect

        protected void connect​(String workingDirectory)
                        throws Exception
        Connect this WindowsSession to 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

        protected void connect​(String workingDirectory,
                               Properties environment)
                        throws IOException
        Connect this WindowsSession to the remote Windows platform. The working directory will be the specified directory.
        Parameters:
        workingDirectory - the working directory for this session
        environment - the environment variables to set for the session
        Throws:
        IOException - if the connection fails
        IllegalStateException - if this session is already connected
      • readOutputStreams

        protected com.microsoft.wsman.shell.ReceiveResponse readOutputStreams()
                                                                       throws IOException
        Read the output from the current commands stdout and stderr streams.
        Returns:
        the ReceiveResponse containing the stdout and stderr streams
        Throws:
        IOException - if an error occurs
      • findFirst

        protected <T> T findFirst​(Collection<?> collection,
                                  Class<T> type)
      • 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 - the Options for waiting, including Timeout
        Returns:
        the exit value from the currently executing command