final ClientChannel channel = session.createChannel("exec", writer.toString().concat(NEW_LINE)); channel.setIn(new ByteArrayInputStream(new byte[0])); final ByteArrayOutputStream sout = new ByteArrayOutputStream();
final ClientChannel channel = session.createChannel("exec", writer.toString().concat(NEW_LINE)); channel.setIn(new ByteArrayInputStream(new byte[0])); final ByteArrayOutputStream sout = new ByteArrayOutputStream();
final ClientChannel channel = session.createChannel("exec", cmd.concat(NEW_LINE)); channel.setIn(new ByteArrayInputStream(new byte[0])); final ByteArrayOutputStream sout = new ByteArrayOutputStream();
final ClientChannel channel = session.createChannel("exec", cmd.concat(NEW_LINE)); channel.setIn(new ByteArrayInputStream(new byte[0])); final ByteArrayOutputStream sout = new ByteArrayOutputStream();
channel = session.createChannel(Channel.CHANNEL_EXEC, command); in = new ByteArrayInputStream(new byte[]{0}); } else if (Channel.CHANNEL_SHELL.equals(endpoint.getChannelType())) { channel = session.createChannel(Channel.CHANNEL_SHELL); in = new PipedInputStream(reply);
sshSession.auth().verify(); if (command != null) { ClientChannel channel = sshSession.createChannel("exec", command + "\n"); channel.setIn(new ByteArrayInputStream(new byte[0])); channel.setOut(new NoCloseOutputStream(stdout));
sshSession.auth().verify(); if (command != null) { ClientChannel channel = sshSession.createChannel("exec", command + "\n"); channel.setIn(new ByteArrayInputStream(new byte[0])); channel.setOut(new NoCloseOutputStream(stdout));
ClientChannel channel = sshSession.createChannel("exec", sb.append("\n").toString()); channel.setIn(new ByteArrayInputStream(new byte[0])); channel.setOut(new NoCloseOutputStream(System.out));
@Test public void testIdleClient() throws Exception { SshClient client = setupTestClient(); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.containsAll(EnumSet.of(ClientChannelEvent.CLOSED))); } } finally { client.stop(); } }
@Test public void testIdleClient() throws Exception { SshClient client = setupTestClient(); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.containsAll(EnumSet.of(ClientChannelEvent.CLOSED))); } } finally { client.stop(); } }
@Test public void testShellClosedOnClientTimeout() throws Exception { TestEchoShell.latch = new CountDownLatch(1); SshClient client = setupTestClient(); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream()) { channel.setOut(out); channel.setErr(err); channel.open().verify(9L, TimeUnit.SECONDS); assertTrue("Latch time out", TestEchoShell.latch.await(10L, TimeUnit.SECONDS)); Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.containsAll( EnumSet.of(ClientChannelEvent.CLOSED, ClientChannelEvent.OPENED))); } } finally { TestEchoShell.latch = null; client.stop(); } }
ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { channel.setOut(out); channel.setErr(err);
ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { channel.setOut(out); channel.setErr(err);
ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { channel.setOut(out); channel.setErr(err);
@Test public void testShellClosedOnClientTimeout() throws Exception { TestEchoShell.latch = new CountDownLatch(1); SshClient client = setupTestClient(); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream()) { channel.setOut(out); channel.setErr(err); channel.open().verify(9L, TimeUnit.SECONDS); assertTrue("Latch time out", TestEchoShell.latch.await(10L, TimeUnit.SECONDS)); Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.containsAll( EnumSet.of(ClientChannelEvent.CLOSED, ClientChannelEvent.OPENED))); } } finally { TestEchoShell.latch = null; client.stop(); } }
@Test public void testShellClosedOnClientTimeout() throws Exception { TestEchoShell.latch = new CountDownLatch(1); SshClient client = setupTestClient(); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream()) { channel.setOut(out); channel.setErr(err); channel.open().verify(9L, TimeUnit.SECONDS); assertTrue("Latch time out", TestEchoShell.latch.await(10L, TimeUnit.SECONDS)); Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.containsAll( EnumSet.of(ClientChannelEvent.CLOSED, ClientChannelEvent.OPENED))); } } finally { TestEchoShell.latch = null; client.stop(); } }
@Test public void testIdleClient() throws Exception { SshClient client = setupTestClient(); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.containsAll(EnumSet.of(ClientChannelEvent.CLOSED))); } } finally { client.stop(); } }
@Test public void testClientWithHeartBeat() throws Exception { SshClient client = setupTestClient(); PropertyResolverUtils.updateProperty(client, ClientFactoryManager.HEARTBEAT_INTERVAL, HEARTBEAT); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.contains(ClientChannelEvent.TIMEOUT)); } } finally { client.stop(); } }
@Test public void testClientWithHeartBeat() throws Exception { SshClient client = setupTestClient(); PropertyResolverUtils.updateProperty(client, ClientFactoryManager.HEARTBEAT_INTERVAL, HEARTBEAT); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.contains(ClientChannelEvent.TIMEOUT)); } } finally { client.stop(); } }
@Test public void testClientWithHeartBeat() throws Exception { SshClient client = setupTestClient(); PropertyResolverUtils.updateProperty(client, ClientFactoryManager.HEARTBEAT_INTERVAL, HEARTBEAT); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (ClientChannel channel = session.createChannel(Channel.CHANNEL_SHELL)) { Collection<ClientChannelEvent> result = channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), WAIT); assertTrue("Wrong channel state: " + result, result.contains(ClientChannelEvent.TIMEOUT)); } } finally { client.stop(); } }