@Override public void start() throws Exception { ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions( new TelnetTermOptions().setHost("localhost").setPort(3000) )); service.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(); } }); } }
@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()); } }); } }
@Override public void start() throws Exception { ShellServer server = ShellServer.create(vertx); AtomicInteger ai = new AtomicInteger(0); server.shellHandler(shell -> { shell.setPrompt(s -> { try { return "C: " + ai.incrementAndGet(); }); }); TelnetTermOptions tto = new TelnetTermOptions().setPort(3000).setHost("localhost"); TermServer telnetTermServer = TermServer.createTelnetTermServer(vertx,tto); server.registerTermServer(telnetTermServer); server.registerCommandResolver(CommandResolver.baseCommands(vertx)); server.listen(ar -> { if (!ar.succeeded()) { ar.cause().printStackTrace();
@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()); } }); } }
/** * Like {@link #create(Vertx, ShellServiceOptions)}, with default options. */ static ShellService create(Vertx vertx) { return create(vertx, new ShellServiceOptions()); }
/** * Start the shell service, this is an asynchronous start. * @param startHandler handler for getting notified when service is started */ public void start(Handler<AsyncResult<Void>> startHandler) { delegate.start(startHandler); }
/** * Close the shell server, this is an asynchronous close. * * @param completionHandler handler for getting notified when service is stopped */ void close(Handler<AsyncResult<Void>> completionHandler);
/** * Stop the shell service, this is an asynchronous stop. */ public void stop() { delegate.stop(); }
/** * Start the shell service, this is an asynchronous start. * @param listenHandler handler for getting notified when service is started * @return */ public io.vertx.rxjava.ext.shell.ShellServer listen(Handler<AsyncResult<Void>> listenHandler) { delegate.listen(listenHandler); return this; }
/** * Called when a new shell is created. Can be used to prepopulate the shell session with objects * or set the prompt. * @param shellHandler handler for getting notified when the server creates a new shell. */ public void shellHandler(Handler<io.vertx.rxjava.ext.shell.Shell> shellHandler) { delegate.shellHandler(new Handler<io.vertx.ext.shell.Shell>() { public void handle(io.vertx.ext.shell.Shell event) { shellHandler.handle(io.vertx.rxjava.ext.shell.Shell.newInstance(event)); } }); }
/** * Close the shell. */ public void close() { delegate.close(); }
@Override public void start() throws Exception { Command starwars = CommandBuilder.command("echokeyboard"). processHandler(process -> { // Echo process.stdinHandler(keys -> { process.write(keys.replace('\r', '\n')); }); // Terminate when user hits Ctrl-C process.interruptHandler(v -> { process.end(); }); }).build(vertx); ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions( new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) { ar.cause().printStackTrace(); } }); } }
/** * Start the shell service, this is an asynchronous start. */ public void start() { delegate.start(); }
/** * Close the shell server, this is an asynchronous close. * @param completionHandler handler for getting notified when service is stopped */ public void close(Handler<AsyncResult<Void>> completionHandler) { delegate.close(completionHandler); }
/** * Stop the shell service, this is an asynchronous start. * @param stopHandler handler for getting notified when service is stopped */ public void stop(Handler<AsyncResult<Void>> stopHandler) { delegate.stop(stopHandler); }
Command starwars = CommandBuilder.command("starwars"). processHandler(process -> { NetClient client = process.vertx().createNetClient(); client.connect(23, "towel.blinkenlights.nl", ar -> { if (ar.succeeded()) { process.interruptHandler(v -> { socket.close(); }); process.write(buff.toString("UTF-8")); }).exceptionHandler(err -> { err.printStackTrace(); process.end(); }); } else { process.write("Could not connect to remote Starwars server\n").end(); }).build(vertx); ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions( new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) { ar.cause().printStackTrace();
@Override public void stop(Handler<AsyncResult<Void>> stopHandler) { server.close(stopHandler); } }
@Override public void start() throws Exception { Command starwars = CommandBuilder.command("top"). processHandler(process -> { long id = process.vertx().setPeriodic(500, id_ -> { StringBuilder buf = new StringBuilder(); Formatter formatter = new Formatter(buf); for (int i = 1; i <= process.height(); i++) { process.write(buf.toString()); }); process.interruptHandler(v -> { vertx.cancelTimer(id); process.end(); }); }).build(vertx); ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions( new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) { ar.cause().printStackTrace();
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) { 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();