org.apache.sshd.server.ExitCallback Java Examples

The following examples show how to use org.apache.sshd.server.ExitCallback. 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: SshShellRunnable.java    From ssh-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
public SshShellRunnable(SshShellProperties properties, ChannelSession session,
                        SshShellListenerService shellListenerService, Banner shellBanner,
                        PromptProvider promptProvider, Shell shell,
                        JLineShellAutoConfiguration.CompleterAdapter completerAdapter, Parser parser,
                        Environment environment, org.apache.sshd.server.Environment sshEnv,
                        SshShellCommandFactory sshShellCommandFactory, InputStream is,
                        OutputStream os, ExitCallback ec) {
    this.properties = properties;
    this.session = session;
    this.shellListenerService = shellListenerService;
    this.shellBanner = shellBanner;
    this.promptProvider = promptProvider;
    this.shell = shell;
    this.completerAdapter = completerAdapter;
    this.parser = parser;
    this.environment = environment;
    this.sshEnv = sshEnv;
    this.sshShellCommandFactory = sshShellCommandFactory;
    this.is = is;
    this.os = os;
    this.ec = ec;
}
 
Example #2
Source File: AbstractSftpProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a pipe thread that connects an input to an output
 *
 * @param name     The name of the thread (for debugging purposes)
 * @param in       The input stream
 * @param out      The output stream
 * @param callback An object whose method {@linkplain ExitCallback#onExit(int)} will be called when the pipe is
 *                 broken. The integer argument is 0 if everything went well.
 */
private static void connect(final String name, final InputStream in, final OutputStream out,
                            final ExitCallback callback) {
    final Thread thread = new Thread((Runnable) () -> {
        int code = 0;
        try {
            final byte buffer[] = new byte[1024];
            int len;
            while ((len = in.read(buffer, 0, buffer.length)) != -1) {
                out.write(buffer, 0, len);
                out.flush();
            }
        } catch (final SshException ex1) {
            // Nothing to do, this occurs when the connection
            // is closed on the remote side
        } catch (final IOException ex2) {
            if (!ex2.getMessage().equals("Pipe closed")) {
                code = -1;
            }
        }
        if (callback != null) {
            callback.onExit(code);
        }
    }, name);
    thread.setDaemon(true);
    thread.start();
}
 
Example #3
Source File: TestNewScpCommand.java    From artifactory_ssh_proxy with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"boxing", "resource"})
NewScpCommand getFailureScpCommand(int returnVal, ExitCallback callback) throws IOException {
    String filePath = "/mep-testing-gradle/foo/bar/maven-metadata.xml";
    FileSystemView viewMock = Mockito.mock(FileSystemView.class);

    Mockito.when(viewMock.getFile(Matchers.any(SshFile.class), Matchers.anyString())).thenReturn(null);

    OutputStream osMock = Mockito.mock(OutputStream.class);
    InputStream isMock = Mockito.mock(InputStream.class);
    LoggingHelper loggingHelper = Mockito.mock(LoggingHelper.class);

    Mockito.when(isMock.read()).thenReturn(returnVal);

    final NewScpHelper helperMocked = new NewScpHelper(isMock, osMock, viewMock, loggingHelper, null, null) {
        @Override
        public String readLine() throws IOException {
            return "filename";
        }

    };


    SshRequestLog requestLog = Mockito.mock(SshRequestLog.class);
    NewScpCommand scpCommand = new NewScpCommand("scp -t " + filePath, requestLog, null) {
        @Override
        protected NewScpHelper createScpHelper() {
            return helperMocked;
        }
    };

    scpCommand.setFileSystemView(viewMock);
    scpCommand.setOutputStream(osMock);
    scpCommand.setInputStream(isMock);
    scpCommand.setExitCallback(callback);

    return scpCommand;
}
 
Example #4
Source File: TestNewScpCommand.java    From artifactory_ssh_proxy with Apache License 2.0 5 votes vote down vote up
@Test
public void testFileFailure() throws IOException {
    ExitCallback callback = Mockito.mock(ExitCallback.class);
    NewScpCommand scpCommand = getFailureScpCommand((int) 'C', callback);
    scpCommand.run();

    Mockito.verify(callback).onExit(Matchers.anyInt(), Matchers.anyString());
}
 
Example #5
Source File: REPLCommandProcessor.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
public REPLCommandProcessor(String prompt, KeyMap keyMap, CommandProcessor commandProcessor,
                            InputStream stdin, OutputWriterImpl outputWriter, ExitCallback exitCallback) {
    this.stdin = stdin;
    this.outputWriter = outputWriter;
    this.exitCallback = exitCallback;
    this.commandProcessor = commandProcessor;
    this.keyMap = keyMap;
    this.prompt = prompt;
    this.charset = Charset.forName("UTF-8");
}
 
Example #6
Source File: SshEchoCommandFactory.java    From ExpectIt with Apache License 2.0 5 votes vote down vote up
@Override
public Command create() {
    return new Command() {
        @Override
        public void setInputStream(InputStream in) {
            SshEchoCommandFactory.this.in = in;
        }

        @Override
        public void setOutputStream(OutputStream out) {
            SshEchoCommandFactory.this.out = out;
        }

        @Override
        public void setErrorStream(OutputStream err) {

        }

        @Override
        public void setExitCallback(ExitCallback callback) {

        }

        @Override
        public void start(Environment env) throws IOException {
            executor.scheduleWithFixedDelay(
                    SshEchoCommandFactory.this,
                    0,
                    100,
                    TimeUnit.MILLISECONDS);
        }

        @Override
        public void destroy() {
            executor.shutdownNow();
        }
    };
}
 
Example #7
Source File: SshClientCommandProcessor.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
public SshClientCommandProcessor(InputStream stdin, OutputWriterImpl outputWriter,
                                 ExitCallback exitCallback, CommandProcessor commandProcessor, KeyMap keyMap) {
    this.stdin = stdin;
    this.outputWriter = outputWriter;
    this.exitCallback = exitCallback;
    this.commandProcessor = commandProcessor;
    this.keyMap = keyMap;
    this.charset = Charset.forName("UTF-8");
}
 
Example #8
Source File: TestNewScpCommand.java    From artifactory_ssh_proxy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDirFailure() throws IOException {
    ExitCallback callback = Mockito.mock(ExitCallback.class);
    NewScpCommand scpCommand = getFailureScpCommand((int) 'D', callback);
    scpCommand.run();

    Mockito.verify(callback).onExit(Matchers.anyInt(), Matchers.anyString());
}
 
Example #9
Source File: AdminCommand.java    From gameserver with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
}
 
Example #10
Source File: WindowAdjustTest.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    // ignored
}
 
Example #11
Source File: GroovyShellWrapper.java    From artifactory_ssh_proxy with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #12
Source File: ForwardingShellWrapper.java    From artifactory_ssh_proxy with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #13
Source File: MkdirCommand.java    From artifactory_ssh_proxy with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #14
Source File: SshdServerMock.java    From gerrit-events with MIT License 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback exitCallback) {
    this.exitCallback = exitCallback;
}
 
Example #15
Source File: NetconfSshdTestSubsystem.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #16
Source File: OpenEJBCommands.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    cbk = callback;
}
 
Example #17
Source File: EmbeddedSSHServer.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #18
Source File: ConsoleCommandFactory.java    From Bukkit-SSHD with Apache License 2.0 4 votes vote down vote up
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #19
Source File: ConsoleShellFactory.java    From Bukkit-SSHD with Apache License 2.0 4 votes vote down vote up
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #20
Source File: Server.java    From sftpserver with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(final ExitCallback callback) {
	this.callback = callback;
}
 
Example #21
Source File: SshClientSessionImpl.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
public SshClientSessionImpl(long sessionId, OutputStream stdout, ExitCallback exitCallback) {
    this.sessionId = sessionId;
    this.stdout = stdout;
    this.exitCallback = exitCallback;
}
 
Example #22
Source File: WindowAdjustTest.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    // ignored
}
 
Example #23
Source File: EchoShell.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #24
Source File: AsyncEchoShellFactory.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #25
Source File: SshShellCommandFactory.java    From ssh-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback ec) {
    SSH_IO_CONTEXT.get().setEc(ec);
}
 
Example #26
Source File: GitSshCommandCreator.java    From onedev with MIT License 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback exitCallBack) {
	this.exitCallBack = exitCallBack;
}
 
Example #27
Source File: DisableShellAccess.java    From onedev with MIT License 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}
 
Example #28
Source File: SingleCommand.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback exitCallback) {
    this.exitCallback = exitCallback;
}
 
Example #29
Source File: SshClientCommand.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback exitCallback) {
    this.exitCallback = exitCallback;
}
 
Example #30
Source File: AsyncEchoShellFactory.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setExitCallback(ExitCallback callback) {
    this.callback = callback;
}