Package org.apache.sshd.client.future

Examples of org.apache.sshd.client.future.OpenFuture


    @Override
    public void sessionCreated(IoSession session) throws Exception {
        ChannelForwardedTcpip channel = new ChannelForwardedTcpip(session);
        session.setAttribute(ChannelForwardedTcpip.class, channel);
        this.session.registerChannel(channel);
        OpenFuture future = channel.open().await();
        Throwable t = future.getException();
        if (t instanceof Exception) {
            throw (Exception) t;
        } else if (t != null) {
            throw new Exception(t);
        }
View Full Code Here


        session.authPassword("smx", "smx").await();
        ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
        channel.setIn(new ByteArrayInputStream(new byte[0]));
        channel.setOut(new ByteArrayOutputStream());
        channel.setErr(new ByteArrayOutputStream());
        OpenFuture openFuture = channel.open();
        CloseFuture closeFuture = session.close(false);
        openFuture.await();
        closeFuture.await();
        assertNotNull(openFuture.isOpened());
        assertTrue(closeFuture.isClosed());
    }
View Full Code Here

        session.authPassword("smx", "smx").await();
        ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
        channel.setIn(new ByteArrayInputStream(new byte[0]));
        channel.setOut(new ByteArrayOutputStream());
        channel.setErr(new ByteArrayOutputStream());
        OpenFuture openFuture = channel.open();
        CloseFuture closeFuture = session.close(true);
        openFuture.await();
        closeFuture.await();
        assertNotNull(openFuture.getException());
        assertTrue(closeFuture.isClosed());
    }
View Full Code Here

        channel.setOut(out);

        ByteArrayOutputStream err = new ByteArrayOutputStream();
        channel.setErr(err);

        OpenFuture openFuture = channel.open();
        openFuture.await(getTimeout());
        if (openFuture.isOpened()) {
            channel.waitFor(ClientChannel.CLOSED, 0);
            result = out.toByteArray();
        }

        return result;
View Full Code Here

    public ChannelDirectTcpip() {
    }

    protected OpenFuture doInit(Buffer buffer) {
        final OpenFuture f = new DefaultOpenFuture(this);
        String hostToConnect = buffer.getString();
        int portToConnect = buffer.getInt();
        InetSocketAddress address;

        try {
            address = new InetSocketAddress(hostToConnect, portToConnect);
        } catch (RuntimeException e) {
            address = null;
        }

        final ServerSession serverSession = (ServerSession)getSession();
        final ForwardingFilter filter = serverSession.getServerFactoryManager().getForwardingFilter();
        if (address == null || filter == null || !filter.canConnect(address, serverSession)) {
            super.close(true);
            f.setException(new OpenChannelException(SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "connect denied"));
            return f;
        }

        String originatorIpAddress = buffer.getString();
        int originatorPort = buffer.getInt();
        log.info("Receiving request for direct tcpip: hostToConnect={}, portToConnect={}, originatorIpAddress={}, originatorPort={}",
                new Object[] { hostToConnect, portToConnect, originatorIpAddress, originatorPort });
        connector = new NioSocketConnector();
        out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
        IoHandler handler = new IoHandlerAdapter() {
            @Override
            public void messageReceived(IoSession session, Object message) throws Exception {
                IoBuffer ioBuffer = (IoBuffer) message;
                int r = ioBuffer.remaining();
                byte[] b = new byte[r];
                ioBuffer.get(b, 0, r);
                out.write(b, 0, r);
                out.flush();
            }

            @Override
            public void sessionClosed(IoSession session) throws Exception {
                sendEof();
            }
        };
        connector.setHandler(handler);
        ConnectFuture future = connector.connect(address);
        future.addListener(new IoFutureListener<ConnectFuture>() {
            public void operationComplete(ConnectFuture future) {
                if (future.isConnected()) {
                    ioSession = future.getSession();
                    f.setOpened();
                } else if (future.getException() != null) {
                    closeImmediately0();
                    if (future.getException() instanceof ConnectException) {
                        f.setException(new OpenChannelException(
                            SshConstants.SSH_OPEN_CONNECT_FAILED,
                            future.getException().getMessage(),
                            future.getException()));
                    } else {
                        f.setException(future.getException());
                    }
                }
            }
        });
        return f;
View Full Code Here

    @Override
    public void sessionCreated(IoSession session) throws Exception {
        ChannelForwardedX11 channel = new ChannelForwardedX11(session);
        session.setAttribute(ChannelForwardedX11.class, channel);
        this.session.registerChannel(channel);
        OpenFuture future = channel.open().await();
        Throwable t = future.getException();
        if (t instanceof Exception) {
            throw (Exception) t;
        } else if (t != null) {
            throw new Exception(t);
        }
View Full Code Here

    public void handleOpenFailure(Buffer buffer) {
        throw new IllegalStateException();
    }

    protected OpenFuture doInit(Buffer buffer) {
        OpenFuture f = new DefaultOpenFuture(this);
        f.setOpened();
        return f;
    }
View Full Code Here

    @Override
    public void sessionCreated(IoSession session) throws Exception {
        ChannelForwardedTcpip channel = new ChannelForwardedTcpip(session);
        session.setAttribute(ChannelForwardedTcpip.class, channel);
        this.session.registerChannel(channel);
        OpenFuture future = channel.open().await();
        Throwable t = future.getException();
        if (t instanceof Exception) {
            throw (Exception) t;
        } else if (t != null) {
            throw new Exception(t);
        }
View Full Code Here

    public ChannelAgentForwarding() {
    }

    protected OpenFuture doInit(Buffer buffer) {
        final OpenFuture f = new DefaultOpenFuture(this);
        try {
            out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
            authSocket = session.getFactoryManager().getProperties().get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
            pool = Pool.create(AprLibrary.getInstance().getRootPool());
            handle = Local.create(authSocket, pool);
            int result = Local.connect(handle, 0);
            if (result != Status.APR_SUCCESS) {
                throwException(result);
            }
            thread = new Thread() {
                public void run() {
                    try {
                        byte[] buf = new byte[1024];
                        while (true) {
                            int len = Socket.recv(handle, buf, 0, buf.length);
                            if (len > 0) {
                                out.write(buf, 0, len);
                                out.flush();
                            }
                        }
                    } catch (IOException e) {
                        close(true);
                    }
                }
            };
            thread.start();
            f.setOpened();

        } catch (Exception e) {
            f.setException(e);
        }
        return f;
    }
View Full Code Here

                                    break;
                                }
                                Socket.timeoutSet(clientSock, 10000000);
                                AgentForwardedChannel channel = new AgentForwardedChannel(clientSock);
                                AgentForwardSupport.this.session.registerChannel(channel);
                                OpenFuture future = channel.open().await();
                                Throwable t = future.getException();
                                if (t instanceof Exception) {
                                    throw (Exception) t;
                                } else if (t != null) {
                                    throw new Exception(t);
                                }
View Full Code Here

TOP

Related Classes of org.apache.sshd.client.future.OpenFuture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.