org.apache.sshd.client.channel.ChannelShell Java Examples
The following examples show how to use
org.apache.sshd.client.channel.ChannelShell.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowTest.java From termd with Apache License 2.0 | 4 votes |
@Test public void testWindowConsumptionWithInvertedStreams() throws Exception { sshd.setShellFactory(new AsyncEchoShellFactory()); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); 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 (ChannelShell channel = session.createShellChannel()) { channel.open().verify(5L, TimeUnit.SECONDS); try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) { Window clientLocal = channel.getLocalWindow(); Window clientRemote = channel.getRemoteWindow(); Window serverLocal = serverChannel.getLocalWindow(); Window serverRemote = serverChannel.getRemoteWindow(); final String message = "0123456789"; final int nbMessages = 500; try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(channel.getInvertedIn())); BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInvertedOut()))) { for (int i = 0; i < nbMessages; i++) { writer.write(message); writer.write("\n"); writer.flush(); waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); String line = reader.readLine(); assertEquals("Mismatched message at line #" + i, message, line); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L)); } } } } } finally { client.stop(); } }
Example #2
Source File: WindowTest.java From termd with Apache License 2.0 | 4 votes |
@Test public void testWindowConsumptionWithDirectStreams() throws Exception { sshd.setShellFactory(new AsyncEchoShellFactory()); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); 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 (ChannelShell channel = session.createShellChannel(); PipedInputStream inPis = new PipedInputStream(); PipedOutputStream inPos = new PipedOutputStream(inPis); PipedInputStream outPis = new PipedInputStream(); PipedOutputStream outPos = new PipedOutputStream(outPis)) { channel.setIn(inPis); channel.setOut(outPos); channel.open().verify(7L, TimeUnit.SECONDS); try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) { Window clientLocal = channel.getLocalWindow(); Window clientRemote = channel.getRemoteWindow(); Window serverLocal = serverChannel.getLocalWindow(); Window serverRemote = serverChannel.getRemoteWindow(); final String message = "0123456789"; final int nbMessages = 500; try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(inPos)); BufferedReader reader = new BufferedReader(new InputStreamReader(outPis))) { for (int i = 0; i < nbMessages; i++) { writer.write(message); writer.write('\n'); writer.flush(); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); String line = reader.readLine(); assertEquals("Mismatched message at line #" + i, message, line); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L)); } } } } } finally { client.stop(); } }
Example #3
Source File: WindowTest.java From termd with Apache License 2.0 | 4 votes |
@Test public void testWindowConsumptionWithAsyncStreams() throws Exception { sshd.setShellFactory(new AsyncEchoShellFactory()); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); 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 (ChannelShell channel = session.createShellChannel()) { channel.setStreaming(ClientChannel.Streaming.Async); channel.open().verify(5L, TimeUnit.SECONDS); try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) { Window clientLocal = channel.getLocalWindow(); Window clientRemote = channel.getRemoteWindow(); Window serverLocal = serverChannel.getLocalWindow(); Window serverRemote = serverChannel.getRemoteWindow(); final String message = "0123456789\n"; final byte[] bytes = message.getBytes(StandardCharsets.UTF_8); final int nbMessages = 500; IoOutputStream output = channel.getAsyncIn(); IoInputStream input = channel.getAsyncOut(); for (int i = 0; i < nbMessages; i++) { Buffer buffer = new ByteArrayBuffer(bytes); output.write(buffer).verify(5L, TimeUnit.SECONDS); waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); Buffer buf = new ByteArrayBuffer(16); IoReadFuture future = input.read(buf); future.verify(5L, TimeUnit.SECONDS); assertEquals("Mismatched available data at line #" + i, message.length(), buf.available()); assertEquals("Mismatched data at line #" + i, message, new String(buf.array(), buf.rpos(), buf.available())); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L)); } } } } finally { client.stop(); } }
Example #4
Source File: WindowTest.java From termd with Apache License 2.0 | 4 votes |
@Test public void testWindowConsumptionWithInvertedStreams() throws Exception { sshd.setShellFactory(new AsyncEchoShellFactory()); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); 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 (ChannelShell channel = session.createShellChannel()) { channel.open().verify(5L, TimeUnit.SECONDS); try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) { Window clientLocal = channel.getLocalWindow(); Window clientRemote = channel.getRemoteWindow(); Window serverLocal = serverChannel.getLocalWindow(); Window serverRemote = serverChannel.getRemoteWindow(); final String message = "0123456789"; final int nbMessages = 500; try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(channel.getInvertedIn())); BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInvertedOut()))) { for (int i = 0; i < nbMessages; i++) { writer.write(message); writer.write("\n"); writer.flush(); waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); String line = reader.readLine(); assertEquals("Mismatched message at line #" + i, message, line); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L)); } } } } } finally { client.stop(); } }
Example #5
Source File: WindowTest.java From termd with Apache License 2.0 | 4 votes |
@Test public void testWindowConsumptionWithDirectStreams() throws Exception { sshd.setShellFactory(new AsyncEchoShellFactory()); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); 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 (ChannelShell channel = session.createShellChannel(); PipedInputStream inPis = new PipedInputStream(); PipedOutputStream inPos = new PipedOutputStream(inPis); PipedInputStream outPis = new PipedInputStream(); PipedOutputStream outPos = new PipedOutputStream(outPis)) { channel.setIn(inPis); channel.setOut(outPos); channel.open().verify(7L, TimeUnit.SECONDS); try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) { Window clientLocal = channel.getLocalWindow(); Window clientRemote = channel.getRemoteWindow(); Window serverLocal = serverChannel.getLocalWindow(); Window serverRemote = serverChannel.getRemoteWindow(); final String message = "0123456789"; final int nbMessages = 500; try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(inPos)); BufferedReader reader = new BufferedReader(new InputStreamReader(outPis))) { for (int i = 0; i < nbMessages; i++) { writer.write(message); writer.write('\n'); writer.flush(); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); String line = reader.readLine(); assertEquals("Mismatched message at line #" + i, message, line); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L)); } } } } } finally { client.stop(); } }
Example #6
Source File: WindowTest.java From termd with Apache License 2.0 | 4 votes |
@Test public void testWindowConsumptionWithAsyncStreams() throws Exception { sshd.setShellFactory(new AsyncEchoShellFactory()); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); 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 (ChannelShell channel = session.createShellChannel()) { channel.setStreaming(ClientChannel.Streaming.Async); channel.open().verify(5L, TimeUnit.SECONDS); try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) { Window clientLocal = channel.getLocalWindow(); Window clientRemote = channel.getRemoteWindow(); Window serverLocal = serverChannel.getLocalWindow(); Window serverRemote = serverChannel.getRemoteWindow(); final String message = "0123456789\n"; final byte[] bytes = message.getBytes(StandardCharsets.UTF_8); final int nbMessages = 500; IoOutputStream output = channel.getAsyncIn(); IoInputStream input = channel.getAsyncOut(); for (int i = 0; i < nbMessages; i++) { Buffer buffer = new ByteArrayBuffer(bytes); output.write(buffer).verify(5L, TimeUnit.SECONDS); waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); Buffer buf = new ByteArrayBuffer(16); IoReadFuture future = input.read(buf); future.verify(5L, TimeUnit.SECONDS); assertEquals("Mismatched available data at line #" + i, message.length(), buf.available()); assertEquals("Mismatched data at line #" + i, message, new String(buf.array(), buf.rpos(), buf.available())); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L)); } } } } finally { client.stop(); } }
Example #7
Source File: MockClientSession.java From xenon with Apache License 2.0 | 4 votes |
@Override public ChannelShell createShellChannel() throws IOException { throw new RuntimeException("Not implemented"); }
Example #8
Source File: MockClientSession.java From xenon with Apache License 2.0 | 4 votes |
@Override public ChannelShell createShellChannel(PtyChannelConfigurationHolder ptyConfig, Map<String, ?> env) throws IOException { // TODO Auto-generated method stub return null; }