@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(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()); } }); }
public TelnetTermServer(Vertx vertx, TelnetTermOptions options) { this.vertx = vertx; this.options = new TelnetTermOptions(options); }
@Test public void testOutBinaryFalse(TestContext context) throws Exception { byte[] expected = StandardCharsets.US_ASCII.encode("€").array(); startTelnet(context, new TelnetTermOptions().setOutBinary(false), term -> { term.write("\u20AC"); }); client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false)); client.connect("localhost", server.actualPort()); InputStream in = client.getInputStream(); for (int i = 0;i < expected.length;i++) { context.assertEquals((int)expected[i], in.read()); } }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, TelnetTermOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "charset": if (member.getValue() instanceof String) { obj.setCharset((String)member.getValue()); } break; case "inBinary": if (member.getValue() instanceof Boolean) { obj.setInBinary((Boolean)member.getValue()); } break; case "intputrc": if (member.getValue() instanceof String) { obj.setIntputrc((String)member.getValue()); } break; case "outBinary": if (member.getValue() instanceof Boolean) { obj.setOutBinary((Boolean)member.getValue()); } break; } } }
@Test public void testKeymapFromFilesystem(TestContext context) throws Exception { URL url = TermServer.class.getResource(SSHTermOptions.DEFAULT_INPUTRC); File f = new File(url.toURI()); startTelnet(context, new TelnetTermOptions().setIntputrc(f.getAbsolutePath()), Term::close); client.connect("localhost", server.actualPort()); } }
@Test public void testDifferentCharset(TestContext context) throws Exception { CompletableFuture<Void> closeLatch = new CompletableFuture<Void>(); startTelnet(context, new TelnetTermOptions().setCharset("ISO_8859_1"), term -> { term.write("\u20AC"); closeLatch.thenAccept(v -> { term.close(); }); }); client.connect("localhost", server.actualPort()); InputStream in = client.getInputStream(); int b = in.read(); context.assertEquals(63, b); closeLatch.complete(null); }
); ShellService service = ShellService.create(vertx, new ShellServiceOptions(). setTelnetOptions(new TelnetTermOptions().setPort(5000)). setSSHOptions(options). setHttpOptions(new HttpTermOptions().
public static void toJson(TelnetTermOptions obj, java.util.Map<String, Object> json) { if (obj.getCharset() != null) { json.put("charset", obj.getCharset()); } json.put("inBinary", obj.getInBinary()); if (obj.getIntputrc() != null) { json.put("intputrc", obj.getIntputrc()); } json.put("outBinary", obj.getOutBinary()); } }
private void startTelnet(TestContext context, TelnetTermOptions options, Handler<Term> termHandler) { server = TermServer.createTelnetTermServer(vertx, options.setPort(4000)); server.termHandler(termHandler); Async async = context.async(); server.listen(context.asyncAssertSuccess(v -> async.complete())); async.awaitSuccess(5000); }
/** * Create a term server for the Telnet protocol. * * @param vertx the vertx instance * @return the term server */ static TermServer createTelnetTermServer(Vertx vertx) { return createTelnetTermServer(vertx, new TelnetTermOptions()); }
@Test public void testOutBinaryTrue(TestContext context) throws Exception { startTelnet(context, new TelnetTermOptions().setOutBinary(true), term -> { term.write("\u20AC"); }); client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false)); client.connect("localhost", server.actualPort()); InputStream in = client.getInputStream(); context.assertEquals(226, in.read()); context.assertEquals(130, in.read()); context.assertEquals(172, in.read()); }
@Override public TermServer listen(Handler<AsyncResult<TermServer>> listenHandler) { Charset charset = Charset.forName(options.getCharset()); if (server == null) { server = vertx.createNetServer(options); Buffer inputrc = Helper.loadResource(vertx.fileSystem(), options.getIntputrc()); if (inputrc == null) { listenHandler.handle(Future.failedFuture("Could not load inputrc from " + options.getIntputrc())); return this; } Keymap keymap = new Keymap(new ByteArrayInputStream(inputrc.getBytes())); TermConnectionHandler connectionHandler = new TermConnectionHandler(vertx, keymap, termHandler); server.connectHandler(new TelnetSocketHandler(vertx, () -> { return new TelnetTtyConnection(options.getInBinary(), options.getOutBinary(), charset, connectionHandler::handle); })); server.listen(ar -> { if (ar.succeeded()) { listenHandler.handle(Future.succeededFuture(this)); } else { listenHandler.handle(Future.failedFuture(ar.cause())); } }); } else { listenHandler.handle(Future.failedFuture("Already started")); } return this; }
}); }); TelnetTermOptions tto = new TelnetTermOptions().setPort(3000).setHost("localhost"); TermServer telnetTermServer = TermServer.createTelnetTermServer(vertx,tto); server.registerTermServer(telnetTermServer);
public ShellServiceOptions(ShellServiceOptions that) { super(that); this.telnetOptions = that.telnetOptions != null ? new TelnetTermOptions(that.telnetOptions) : null; this.sshOptions = that.sshOptions != null ? new SSHTermOptions(that.sshOptions) : null; this.httpOptions = that.httpOptions != null ? new HttpTermOptions(that.httpOptions) : null; }
@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(); } }); } }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, ShellServiceOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "httpOptions": if (member.getValue() instanceof JsonObject) { obj.setHttpOptions(new io.vertx.ext.shell.term.HttpTermOptions((JsonObject)member.getValue())); } break; case "sshOptions": if (member.getValue() instanceof JsonObject) { obj.setSSHOptions(new io.vertx.ext.shell.term.SSHTermOptions((JsonObject)member.getValue())); } break; case "telnetOptions": if (member.getValue() instanceof JsonObject) { obj.setTelnetOptions(new io.vertx.ext.shell.term.TelnetTermOptions((JsonObject)member.getValue())); } break; } } }
new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars);
public static io.vertx.ext.shell.term.TermServer createTelnetTermServer(io.vertx.ext.shell.term.TermServer j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.shell.term.TermServer.createTelnetTermServer(vertx, options != null ? new io.vertx.ext.shell.term.TelnetTermOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } public static io.vertx.ext.shell.term.TermServer createHttpTermServer(io.vertx.ext.shell.term.TermServer j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) {
@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(); } }); } }