@Test public void testRunShell() throws Exception { SSHService sshService = prepareRunShellTest(); CommandResult commandResult = sshService.runShell("ls", "UTF-8", true, CONNECT_TIMEOUT, COMMAND_TIMEOUT, AGENT_FORWARDING_FALSE); assertEquals(0, commandResult.getExitCode()); assertEquals(null, commandResult.getStandardError()); assertEquals("", commandResult.getStandardOutput()); }
@Override public CommandResult runShell( final String command, final String characterSet, boolean usePseudoTerminal, int connectTimeout, int commandTimeout, boolean agentForwarding) { try { if (!isConnected()) { session.connect(connectTimeout); } final ChannelShell channelShell = (ChannelShell) session.openChannel(SHELL_CHANNEL); channelShell.setPty(usePseudoTerminal); channelShell.setAgentForwarding(agentForwarding); final OutputStream shellIn = channelShell.getOutputStream(); final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout); final PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(shellIn, characterSet)); printWriter.println(command); printWriter.flush(); try { Thread.sleep(commandTimeout); } catch (InterruptedException ignored) { } printWriter.println(EXIT_COMMAND); printWriter.flush(); final String result = IOUtils.toString(shellOut, characterSet); final CommandResult commandResult = new CommandResult(); commandResult.setStandardOutput(result); return commandResult; } catch (JSchException | IOException e) { throw new RuntimeException(e); } }
SSHServiceImpl implements SSHService { @Override public CommandResult runShell( final String command, final String characterSet, boolean usePseudoTerminal, int connectTimeout, int commandTimeout, boolean agentForwarding) { try { if (!isConnected()) { session.connect(connectTimeout); } final ChannelShell channelShell = (ChannelShell) session.openChannel(SHELL_CHANNEL); channelShell.setPty(usePseudoTerminal); channelShell.setAgentForwarding(agentForwarding); final OutputStream shellIn = channelShell.getOutputStream(); final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout); final PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(shellIn, characterSet)); printWriter.println(command); printWriter.flush(); try { Thread.sleep(commandTimeout); } catch (InterruptedException ignored) { } printWriter.println(EXIT_COMMAND); printWriter.flush(); final String result = IOUtils.toString(shellOut, characterSet); final CommandResult commandResult = new CommandResult(); commandResult.setStandardOutput(result); return commandResult; } catch (JSchException | IOException e) { throw new RuntimeException(e); } } }
SSHServiceImpl implements SSHService { @Override public CommandResult runShell( final String command, final String characterSet, boolean usePseudoTerminal, int connectTimeout, int commandTimeout, boolean agentForwarding) { try { if (!isConnected()) { session.connect(connectTimeout); } final ChannelShell channelShell = (ChannelShell) session.openChannel(SHELL_CHANNEL); channelShell.setPty(usePseudoTerminal); channelShell.setAgentForwarding(agentForwarding); final OutputStream shellIn = channelShell.getOutputStream(); final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout); final PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(shellIn, characterSet)); printWriter.println(command); printWriter.flush(); try { Thread.sleep(commandTimeout); } catch (InterruptedException ignored) { } printWriter.println(EXIT_COMMAND); printWriter.flush(); final String result = IOUtils.toString(shellOut, characterSet); final CommandResult commandResult = new CommandResult(); commandResult.setStandardOutput(result); return commandResult; } catch (JSchException | IOException e) { throw new RuntimeException(e); } } SSHServiceImpl(Session session, Channel channel);  SSHServiceImpl(ConnectionDetails details, IdentityKey identityKey, KnownHostsFile knownHostsFile,
                          int connectTimeout, boolean keepContextForExpectCommand, ProxyHTTP proxyHTTP, String allowedCiphers); }
SSHServiceImpl implements SSHService { @Override public CommandResult runShell( final String command, final String characterSet, boolean usePseudoTerminal, int connectTimeout, int commandTimeout, boolean agentForwarding) { try { if (!isConnected()) { session.connect(connectTimeout); } final ChannelShell channelShell = (ChannelShell) session.openChannel(SHELL_CHANNEL); channelShell.setPty(usePseudoTerminal); channelShell.setAgentForwarding(agentForwarding); final OutputStream shellIn = channelShell.getOutputStream(); final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout); final PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(shellIn, characterSet)); printWriter.println(command); printWriter.flush(); try { Thread.sleep(commandTimeout); } catch (InterruptedException ignored) { } printWriter.println(EXIT_COMMAND); printWriter.flush(); final String result = IOUtils.toString(shellOut, characterSet); final CommandResult commandResult = new CommandResult(); commandResult.setStandardOutput(result); return commandResult; } catch (JSchException | IOException e) { throw new RuntimeException(e); } } SSHServiceImpl(Session session, Channel channel);  SSHServiceImpl(ConnectionDetails details, IdentityKey identityKey, KnownHostsFile knownHostsFile,
                          int connectTimeout, boolean keepContextForExpectCommand, ProxyHTTP proxyHTTP, String allowedCiphers); @Override CommandResult runShell(
            final String command,
            final String characterSet,
            boolean usePseudoTerminal,
            int connectTimeout,
            int commandTimeout,
            boolean agentForwarding); @Override CommandResult runShellCommand(
            String command,
            String characterSet,
            boolean usePseudoTerminal,
            int connectTimeout,
            int commandTimeout,
            boolean agentForwarding); @Override void createLocalTunnel(int localPort, String remoteHost, int remotePort); @Override boolean isConnected(); @Override void close(); @Override boolean saveToCache(GlobalSessionObject<Map<String, SSHConnection>> sessionParam, String sessionId); @Override void removeFromCache(GlobalSessionObject<Map<String, SSHConnection>> sessionParam, String sessionId); @Override Session getSSHSession(); @Override Channel getExecChannel(); }
SSHServiceImpl implements SSHService { @Override public CommandResult runShell( final String command, final String characterSet, boolean usePseudoTerminal, int connectTimeout, int commandTimeout, boolean agentForwarding) { try { if (!isConnected()) { session.connect(connectTimeout); } final ChannelShell channelShell = (ChannelShell) session.openChannel(SHELL_CHANNEL); channelShell.setPty(usePseudoTerminal); channelShell.setAgentForwarding(agentForwarding); final OutputStream shellIn = channelShell.getOutputStream(); final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout); final PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(shellIn, characterSet)); printWriter.println(command); printWriter.flush(); try { Thread.sleep(commandTimeout); } catch (InterruptedException ignored) { } printWriter.println(EXIT_COMMAND); printWriter.flush(); final String result = IOUtils.toString(shellOut, characterSet); final CommandResult commandResult = new CommandResult(); commandResult.setStandardOutput(result); return commandResult; } catch (JSchException | IOException e) { throw new RuntimeException(e); } } SSHServiceImpl(Session session, Channel channel);  SSHServiceImpl(ConnectionDetails details, IdentityKey identityKey, KnownHostsFile knownHostsFile,
                          int connectTimeout, boolean keepContextForExpectCommand, ProxyHTTP proxyHTTP, String allowedCiphers); @Override CommandResult runShell(
            final String command,
            final String characterSet,
            boolean usePseudoTerminal,
            int connectTimeout,
            int commandTimeout,
            boolean agentForwarding); @Override CommandResult runShellCommand(
            String command,
            String characterSet,
            boolean usePseudoTerminal,
            int connectTimeout,
            int commandTimeout,
            boolean agentForwarding); @Override void createLocalTunnel(int localPort, String remoteHost, int remotePort); @Override boolean isConnected(); @Override void close(); @Override boolean saveToCache(GlobalSessionObject<Map<String, SSHConnection>> sessionParam, String sessionId); @Override void removeFromCache(GlobalSessionObject<Map<String, SSHConnection>> sessionParam, String sessionId); @Override Session getSSHSession(); @Override Channel getExecChannel(); static final String EXIT_COMMAND; }