private void checkConnected() { if (!isConnected()) { throw new IllegalStateException("Not connected"); } }
public void stopClient() { if (client != null && client.isConnected()) { try { client.disconnect(); } catch (IOException e) { throw new RuntimeException(e); } finally { client = null; } } else if (client != null) { client = null; } }
/** * Adds {@code zlib} compression to preferred compression algorithms. There is no guarantee that it will be * successfully negotiatied. * <p/> * If the client is already connected renegotiation is done; otherwise this method simply returns (and compression * will be negotiated during connection establishment). * * @throws ClassNotFoundException if {@code JZlib} is not in classpath * @throws TransportException if an error occurs during renegotiation */ public void useCompression() throws TransportException { trans.getConfig().setCompressionFactories(Arrays.asList( new DelayedZlibCompression.Factory(), new ZlibCompression.Factory(), new NoneCompression.Factory())); if (isConnected()) rekey(); }
@Test public void connected() throws IOException { assertTrue(fixture.getClient().isConnected()); }
@Test public void shouldCorrectlyHandleSessionChannelEof() throws IOException, InterruptedException { fixture.setupConnectedDefaultClient().authPassword("jeroen", "jeroen"); Session session = fixture.getClient().startSession(); session.allocateDefaultPTY(); session.close(); Thread.sleep(1000); assertThat("Should still be connected", fixture.getClient().isConnected()); }
@Test public void shouldVerifyAlgorithm() throws IOException { for (int i = 0; i < 10; i++) { logger.info("--> Attempt {}", i); configureServer(fixture.getServer()); fixture.start(); config.setRandomFactory(randomFactory); Config config = getClientConfig(this.config); SSHClient sshClient = fixture.connectClient(fixture.setupClient(config)); assertThat("should be connected", sshClient.isConnected()); sshClient.disconnect(); // fixture.stopServer(); fixture.stopClient(); } }
private void checkConnected() { if (!isConnected()) { throw new IllegalStateException("Not connected"); } }
private void checkConnected() { if (!isConnected()) { throw new IllegalStateException("Not connected"); } }
@Override public boolean isConnected() { if(super.isConnected()) { return client.isConnected(); } return false; }
@Override public boolean isConnected() { try { return sshClientConnection.getSSHClient().isConnected(); } catch (Exception e) { throw Throwables.propagate(e); } }
private void checkConnected() { checkState(sshClientConnection.ssh != null && sshClientConnection.ssh.isConnected(), String .format("(%s) ssh not connected!", toString())); }
@Override public void clear() { if (ssh != null && ssh.isConnected()) { try { if (LOG.isTraceEnabled()) LOG.trace("Disconnecting SshjClientConnection {} ({})", this, System.identityHashCode(this)); ssh.disconnect(); } catch (IOException e) { if (LOG.isDebugEnabled()) LOG.debug("<< exception disconnecting from {}: {}", e, e.getMessage()); } } ssh = null; }
@Override public boolean isConnected() { try { return sshClientConnection.getSSHClient().isConnected(); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void clear() { if (ssh != null && ssh.isConnected()) { try { if (LOG.isTraceEnabled()) LOG.trace("Disconnecting SshjClientConnection {} ({})", this, System.identityHashCode(this)); ssh.disconnect(); } catch (IOException e) { if (LOG.isDebugEnabled()) LOG.debug("<< exception disconnecting from {}: {}", e, e.getMessage()); } ssh = null; } }
public void dispose(InvocationContext invocationContext) throws GfacException { super.dispose(invocationContext); try { if (ssh != null && ssh.isConnected()) { ssh.disconnect(); } } catch (Exception e) { log.warn("Cannot Close SSH Connection"); } } }
private synchronized void checkConnection() { if (sshClient == null || !sshClient.isConnected() || !sshClient.isAuthenticated()) { log.info("Reconnecting the session for " + user + "@" + ip); close(); establishConnection(); log.info("Reconnected the session for " + user + "@" + ip); } }
public SSHClientMocker setConnected(boolean isConnected) { Mockito.when(client.isConnected()).thenReturn(isConnected); return this; }
@Test(expected = IllegalStateException.class) public void query_no_connection() throws RaspiQueryException { Mockito.when(sshClient.isConnected()).thenReturn(false); raspiQuery.queryVcgencmd(); }
@Test(expected = IllegalStateException.class) public void query_no_auth() throws RaspiQueryException { Mockito.when(sshClient.isConnected()).thenReturn(true); Mockito.when(sshClient.isAuthenticated()).thenReturn(false); raspiQuery.queryVcgencmd(); }
public void testDontThrowIOExceptionOnClear() throws Exception { SshjSshClient ssh1 = createClient(); SSHClient ssh = createMock(SSHClient.class); expect(ssh.isConnected()).andReturn(true); ssh.disconnect(); expectLastCall().andThrow(new ConnectionException("disconnected")); replay(ssh); ssh1.sshClientConnection.ssh = ssh; ssh1.sshClientConnection.clear(); verify(ssh); }