@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); } }
router.route().handler(CookieHandler.create()); router.route().handler(BodyHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(UserSessionHandler.create(authProvider)); router.route("/private/*").handler(RedirectAuthHandler.create(authProvider, "/loginpage.html")); router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private")); router.route("/loginhandler").handler(FormLoginHandler.create(authProvider)); router.route().handler(StaticHandler.create());
@Override public void start() { Router router = Router.router(vertx); // Serve the static pages router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(8080); System.out.println("Server is started"); }
router.route().handler(CookieHandler.create()); router.route().handler(BodyHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(UserSessionHandler.create(authProvider)); BridgeOptions options = new BridgeOptions() .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.listAlbums")) .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.login")) .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.placeOrder") .setRequiredAuthority("place_order")) .addOutboundPermitted(new PermittedOptions()); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options)); router.route().handler(StaticHandler.create());
BridgeOptions options = new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddress("news-feed")); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options, event -> { if (event.type() == BridgeEventType.SOCKET_CREATED) { System.out.println("A socket was created"); event.complete(true); router.route().handler(StaticHandler.create());
@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); } }
@Validate public void start() throws Exception { setUpInitialData(); TcclSwitch.executeWithTCCLSwitch(() -> { Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/products/:productID").handler(this::handleGetProduct); router.put("/products/:productID").handler(this::handleAddProduct); router.get("/products").handler(this::handleListProducts); router.get("/assets/*").handler(StaticHandler.create("assets", this.getClass().getClassLoader())); LOGGER.info("Creating HTTP server for vert.x web application"); HttpServer server = vertx.createHttpServer(); server.requestHandler(router).listen(8081); }); }
@Override public void start() { setUpInitialData(); Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/products/:productID").handler(this::handleGetProduct); router.put("/products/:productID").handler(this::handleAddProduct); router.get("/products").handler(this::handleListProducts); vertx.createHttpServer().requestHandler(router).listen(8080); }
allowedMethods.add(HttpMethod.PUT); router.route().handler(CorsHandler.create("*").allowedHeaders(allowedHeaders).allowedMethods(allowedMethods)); router.route().handler(StaticHandler.create());
router.route().handler(CookieHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(UserSessionHandler.create(authProvider)); OAuth2AuthHandler.create(authProvider) .setupCallback(router.route("/callback")) .addAuthority("user:email") );
@Override public void start() { Router router = Router.router(vertx); // Serve the dynamic pages router.route("/dynamic/*") .handler(ctx -> { // put the context into the template render context ctx.put("context", ctx); ctx.next(); }) .handler(TemplateHandler.create(MVELTemplateEngine.create(vertx))); // Serve the static pages router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(8080); }
router.route("/api/protected").handler(JWTAuthHandler.create(jwt)); router.route("/api/protected/defcon1").handler(JWTAuthHandler.create(jwt).addAuthority("defcon1")); router.route("/api/protected/defcon2").handler(JWTAuthHandler.create(jwt).addAuthority("defcon2")); router.route("/api/protected/defcon3").handler(JWTAuthHandler.create(jwt).addAuthority("defcon3")); router.route().handler(StaticHandler.create());
@Override public void start() throws Exception { Router router = Router.router(vertx); router.route().handler(CookieHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(routingContext -> { Session session = routingContext.session(); Integer cnt = session.get("hitcount"); cnt = (cnt == null ? 0 : cnt) + 1; session.put("hitcount", cnt); routingContext.response().putHeader("content-type", "text/html") .end("<html><body><h1>Hitcount: " + cnt + "</h1></body></html>"); }); vertx.createHttpServer().requestHandler(router).listen(8080); } }
@Override public void start() throws Exception { final Router router = Router.router(vertx); // Populate context with data router.route().handler(ctx -> { ctx.put("title", "Vert.x Web Example Using Rocker"); ctx.put("name", "Rocker"); ctx.next(); }); // Render a custom template. // Note: you need a compile-time generator for Rocker to work properly // See the pom.xml for an example router.route().handler(TemplateHandler.create(RockerTemplateEngine.create())); vertx.createHttpServer().requestHandler(router).listen(8080); } }
@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().handler(CookieHandler.create()); router.route().handler(BodyHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(UserSessionHandler.create(authProvider)); router.route("/private/*").handler(RedirectAuthHandler.create(authProvider, "/loginpage.html")); router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private")); router.route("/loginhandler").handler(FormLoginHandler.create(authProvider)); router.route().handler(StaticHandler.create());
router.route().handler(BodyHandler.create());
@Override public void start() throws Exception { Router router = Router.router(vertx); // Serve the static pages router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(configuration.httpPort()); } }