Search in sources :

Example 6 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class HelloWorldCommand method start.

@Override
public void start() throws Exception {
    Command helloWorld = CommandBuilder.command("hello-world").processHandler(process -> {
        process.write("hello world\n");
        process.end();
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(helloWorld);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) Runner(io.vertx.example.util.Runner) ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Example 7 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class WgetCommand method start.

@Override
public void start() throws Exception {
    // Create the wget CLI
    CLI cli = CLI.create("wget").setSummary("Wget implemented with Vert.x HTTP client").addArgument(new Argument().setIndex(0).setArgName("http-url").setDescription("the HTTP uri to get"));
    // Create the command
    Command helloWorld = CommandBuilder.command(cli).processHandler(process -> {
        URL url;
        try {
            url = new URL(process.commandLine().getArgumentValue(0));
        } catch (MalformedURLException e) {
            process.write("Bad url\n").end();
            return;
        }
        HttpClient client = process.vertx().createHttpClient();
        process.write("Connecting to " + url + "\n");
        int port = url.getPort();
        if (port == -1) {
            port = 80;
        }
        HttpClientRequest req = client.get(port, url.getHost(), url.getPath());
        req.exceptionHandler(err -> {
            process.write("wget: error " + err.getMessage() + "\n");
            process.end();
        });
        req.handler(resp -> {
            process.write(resp.statusCode() + " " + resp.statusMessage() + "\n");
            String contentType = resp.getHeader("Content-Type");
            String contentLength = resp.getHeader("Content-Length");
            process.write("Length: " + (contentLength != null ? contentLength : "unspecified"));
            if (contentType != null) {
                process.write("[" + contentType + "]");
            }
            process.write("\n");
            process.end();
        });
        req.end();
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(helloWorld);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) Argument(io.vertx.core.cli.Argument) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Command(io.vertx.ext.shell.command.Command) CLI(io.vertx.core.cli.CLI) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) Runner(io.vertx.example.util.Runner) HttpClient(io.vertx.core.http.HttpClient) CLI(io.vertx.core.cli.CLI) ShellService(io.vertx.ext.shell.ShellService) MalformedURLException(java.net.MalformedURLException) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Argument(io.vertx.core.cli.Argument) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) HttpClient(io.vertx.core.http.HttpClient) URL(java.net.URL)

Example 8 with TelnetTermOptions

use of io.vertx.ext.shell.term.TelnetTermOptions in project vertx-examples by vert-x3.

the class TermCast method start.

@Override
public void start(Future<Void> startFuture) throws Exception {
    termServer = TermServer.createTelnetTermServer(vertx, new TelnetTermOptions().setHost("localhost").setPort(3000).setInBinary(false));
    Robot robot = new Robot();
    termServer.termHandler(term -> {
        new ScreenCaster(vertx, robot, term).handle();
    });
    termServer.listen(ar -> {
        if (ar.succeeded()) {
            startFuture.complete();
        } else {
            startFuture.fail(ar.cause());
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions)

Aggregations

TelnetTermOptions (io.vertx.ext.shell.term.TelnetTermOptions)8 ShellService (io.vertx.ext.shell.ShellService)6 ShellServiceOptions (io.vertx.ext.shell.ShellServiceOptions)6 AbstractVerticle (io.vertx.core.AbstractVerticle)5 Runner (io.vertx.example.util.Runner)5 Command (io.vertx.ext.shell.command.Command)5 CommandBuilder (io.vertx.ext.shell.command.CommandBuilder)5 CommandRegistry (io.vertx.ext.shell.command.CommandRegistry)5 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2 List (java.util.List)2 Argument (io.vertx.core.cli.Argument)1 CLI (io.vertx.core.cli.CLI)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 NetClient (io.vertx.core.net.NetClient)1 NetSocket (io.vertx.core.net.NetSocket)1 ShellServer (io.vertx.ext.shell.ShellServer)1 TermServer (io.vertx.ext.shell.term.TermServer)1 TelnetTermServer (io.vertx.ext.shell.term.impl.TelnetTermServer)1