Search in sources :

Example 6 with ShellServiceOptions

use of io.vertx.ext.shell.ShellServiceOptions 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 ShellServiceOptions

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

the class RunShell method start.

@Override
public void start(Future<Void> startFuture) throws Exception {
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setHttpOptions(new HttpTermOptions().setHost("localhost").setPort(8080).setAuthOptions(new ShiroAuthOptions().setConfig(new JsonObject().put("properties_path", "auth.properties")))));
    service.start(ar -> {
        if (ar.succeeded()) {
            startFuture.succeeded();
        } else {
            startFuture.fail(ar.cause());
        }
    });
}
Also used : ShellService(io.vertx.ext.shell.ShellService) HttpTermOptions(io.vertx.ext.shell.term.HttpTermOptions) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) ShiroAuthOptions(io.vertx.ext.auth.shiro.ShiroAuthOptions) JsonObject(io.vertx.core.json.JsonObject)

Example 8 with ShellServiceOptions

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

the class RunShell method start.

@Override
public void start(Future<Void> startFuture) throws Exception {
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setSSHOptions(new SSHTermOptions().setHost("localhost").setPort(3000).setKeyPairOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setAuthOptions(new ShiroAuthOptions().setConfig(new JsonObject().put("properties_path", "auth.properties")))));
    service.start(ar -> {
        if (ar.succeeded()) {
            startFuture.succeeded();
        } else {
            startFuture.fail(ar.cause());
        }
    });
}
Also used : ShellService(io.vertx.ext.shell.ShellService) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) ShiroAuthOptions(io.vertx.ext.auth.shiro.ShiroAuthOptions) JksOptions(io.vertx.core.net.JksOptions) JsonObject(io.vertx.core.json.JsonObject) SSHTermOptions(io.vertx.ext.shell.term.SSHTermOptions)

Example 9 with ShellServiceOptions

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

the class RunShell method start.

@Override
public void start(Promise<Void> startPromise) throws Exception {
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setHttpOptions(new HttpTermOptions().setHost("localhost").setPort(8080).setAuthOptions(new ShiroAuthOptions().setConfig(new JsonObject().put("properties_path", "auth.properties")))));
    service.start(startPromise);
}
Also used : ShellService(io.vertx.ext.shell.ShellService) HttpTermOptions(io.vertx.ext.shell.term.HttpTermOptions) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) ShiroAuthOptions(io.vertx.ext.auth.shiro.ShiroAuthOptions) JsonObject(io.vertx.core.json.JsonObject)

Example 10 with ShellServiceOptions

use of io.vertx.ext.shell.ShellServiceOptions 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)

Aggregations

ShellService (io.vertx.ext.shell.ShellService)10 ShellServiceOptions (io.vertx.ext.shell.ShellServiceOptions)10 TelnetTermOptions (io.vertx.ext.shell.term.TelnetTermOptions)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 JsonObject (io.vertx.core.json.JsonObject)4 ShiroAuthOptions (io.vertx.ext.auth.shiro.ShiroAuthOptions)4 JksOptions (io.vertx.core.net.JksOptions)2 HttpTermOptions (io.vertx.ext.shell.term.HttpTermOptions)2 SSHTermOptions (io.vertx.ext.shell.term.SSHTermOptions)2 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