@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddress("feed")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("feed", new JsonObject().put("now", timestamp)); }); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddress("feed")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("feed", new JsonObject().put("now", timestamp)); }); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddress("feed")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("feed", new JsonObject().put("now", timestamp)); }); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("com.example:cmd:poke-server")) .addOutboundPermitted(new PermittedOptions().setAddress("com.example:stat:server-info")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("com.example:stat:server-info", new JsonObject().put("systemTime", timestamp)); }); } }
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("chat.message")) .addOutboundPermitted(new PermittedOptions().setAddress("chat.message")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); } }
SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler);
@Override public void start() throws Exception { // Create the client object MyService service = new MyServiceImpl(); // Register the handler new ServiceBinder(vertx) .setAddress("proxy.example") .register(MyService.class, service); Router router = Router.router(vertx); BridgeOptions options = new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("proxy.example")); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options)); // Serve the static resources router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(8080); } }
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options, event -> {
@Override public void start() throws Exception { // Create the client object ProcessorService service = new ProcessorServiceImpl(); // Register the handler new ServiceBinder(vertx) .setAddress("vertx.processor") .register(ProcessorService.class, service); Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("vertx.processor")) .addOutboundPermitted(new PermittedOptions().setAddress("vertx.processor")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); router.route().handler(StaticHandler.create()); // vertx.createHttpServer().requestHandler(router).listen(8080); }
); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
@Override public void setUp() throws Exception { super.setUp(); sockJSHandler = SockJSHandler.create(vertx); router.route("/eventbus/*").handler(sockJSHandler); }
private void setupSockJsServer(String serverPath, BiConsumer<SockJSSocket, Buffer> serverBufferHandler) { String path = serverPath + "/*"; router.route(path).handler(SockJSHandler.create(vertx) .socketHandler(sock -> { sock.handler(buffer -> serverBufferHandler.accept(sock, buffer)); sock.exceptionHandler(this::fail); })); }
@Test public void testInvalidMessageCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("SockJSHandlerTest.testInvalidMessageCode"))) ); vertx.eventBus().consumer("SockJSHandlerTest.testInvalidMessageCode", msg -> msg.reply(new JsonObject())); client.websocket("/ws-timeout/websocket", ws -> { ws.writeFinalBinaryFrame(Buffer.buffer("durp!")); ws.frameHandler(frame -> { // we should get a normal frame with a error message if (!frame.isClose()) { JsonObject msg = new JsonObject(frame.binaryData()); assertEquals("err", msg.getString("type")); assertEquals("invalid_json", msg.getString("body")); testComplete(); ws.close(); } }); }); await(); } }
router.route("/echo/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> sock.handler(sock::write))); router.route("/close/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> { router.route("/disabled_websocket_echo/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions() .setMaxBytesStreaming(4096).addDisabledTransport("WEBSOCKET")).socketHandler(sock -> sock.handler(sock::write))); router.route("/ticker/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> { long timerID = vertx.setPeriodic(1000, tid -> sock.write(buffer("tick!"))); sock.endHandler(v -> vertx.cancelTimer(timerID)); })); router.route("/amplify/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> sock.handler(data -> { String str = data.toString(); router.route("/broadcast/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(new Handler<SockJSSocket>() { Set<String> connections = new HashSet<>(); router.route("/cookie_needed_echo/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions(). setMaxBytesStreaming(4096).setInsertJSESSIONID(true)).socketHandler(sock -> sock.handler(sock::write)));
@Override public void start() throws Exception { /* test service */ final TestService testService = new TestService(); /* address */ final String address = "testservice"; /* service builder */ final ServiceBuilder serviceBuilder = ServiceBuilder.serviceBuilder(); serviceBuilder.setServiceObject(testService); final ServiceQueue serviceQueue = serviceBuilder.build(); /* vertx event bus bridge to qbit. */ final VertxEventBusBridgeBuilder vertxEventBusBridgeBuilder = VertxEventBusBridgeBuilder .vertxEventBusBridgeBuilder() .setVertx(vertx); vertxEventBusBridgeBuilder.addBridgeAddress(address, TestService.class); final Router router = Router.router(vertx); router.route("/health/").handler(routingContext -> routingContext.response().end("\"ok\"")); /* Configure bridge at this HTTP/WebSocket URI. */ router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge( new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress(address)) .addOutboundPermitted(new PermittedOptions().setAddress(address)) )); vertxEventBusBridgeBuilder.setServiceQueue(serviceQueue); serviceQueue.startAll(); //startall not supported yet for bridge. vertxEventBusBridgeBuilder.build(); vertx.createHttpServer().requestHandler(router::accept).listen(8080); System.out.println("Bound to 8080"); }
@Test public void testTimeoutCloseCode() { router.route("/ws-timeout/*").handler(SockJSHandler .create(vertx) .bridge(new BridgeOptions().setPingTimeout(1)) ); client.websocket("/ws-timeout/websocket", ws -> ws.frameHandler(frame -> { if (frame.isClose()) { assertEquals(1001, frame.closeStatusCode()); assertEquals("Session expired", frame.closeReason()); testComplete(); } })); await(); }
@Test public void testCookiesRemoved() throws Exception { router.route("/cookiesremoved/*").handler(SockJSHandler.create(vertx) .socketHandler(sock -> { MultiMap headers = sock.headers(); String cookieHeader = headers.get("cookie"); assertNotNull(cookieHeader); assertEquals("JSESSIONID=wibble", cookieHeader); testComplete(); })); MultiMap headers = new CaseInsensitiveHeaders(); headers.add("cookie", "JSESSIONID=wibble"); headers.add("cookie", "flibble=floob"); client.websocket("/cookiesremoved/websocket", headers, ws -> { String frame = "foo"; ws.writeFrame(io.vertx.core.http.WebSocketFrame.textFrame(frame, true)); }); await(); }
@Override public void setUp() throws Exception { super.setUp(); sockJSHandler = SockJSHandler.create(vertx); router.route("/eventbus/*").handler(sockJSHandler); }