List of usage examples for io.vertx.core.http HttpMethod GET
HttpMethod GET
To view the source code for io.vertx.core.http HttpMethod GET.
Click Source Link
From source file:org.pac4j.vertx.OAuth2ProviderMimic.java
License:Apache License
private Router router() { Router router = Router.router(vertx); router.route(HttpMethod.GET, OAUTH2_PROVIDER_SUCCESS_ENDPOINT).handler(authSuccessHandler()); router.route(HttpMethod.POST, OAUTH2_PROVIDER_TOKEN_ENDPOINT).handler(bodyHandlerForTokenRequest()); router.route(HttpMethod.GET, OAUTH2_PROVIDER_TOKEN_ENDPOINT).handler(tokenRequestHandler()); router.route(HttpMethod.GET, OAUTH2_PROVIDER_PROFILE_ENDPOINT).handler(profileHandler()); return router; }
From source file:spring.vertxtest.verticle.MyTestVerticle.java
@Override public void start(Future<Void> fut) throws Exception { log.info("start() -- starting Vertx Verticle with eventbus, API handler, and static file handler"); // grab the router router = getRouter();/* w w w .j av a 2 s . c om*/ // enable CORS for the router CorsHandler corsHandler = CorsHandler.create("*"); //Wildcard(*) not allowed if allowCredentials is true corsHandler.allowedMethod(HttpMethod.OPTIONS); corsHandler.allowedMethod(HttpMethod.GET); corsHandler.allowedMethod(HttpMethod.POST); corsHandler.allowedMethod(HttpMethod.PUT); corsHandler.allowedMethod(HttpMethod.DELETE); corsHandler.allowCredentials(false); corsHandler.allowedHeader("Access-Control-Request-Method"); corsHandler.allowedHeader("Access-Control-Allow-Method"); corsHandler.allowedHeader("Access-Control-Allow-Credentials"); corsHandler.allowedHeader("Access-Control-Allow-Origin"); corsHandler.allowedHeader("Access-Control-Allow-Headers"); corsHandler.allowedHeader("Content-Type"); // enable handling of body router.route().handler(BodyHandler.create()); router.route().handler(corsHandler); router.route().handler(this::handleAccessLogging); // publish a payload to provided eventbus destination router.post("/api/eventbus/publish/:destination").handler(this::publish); // open up all for outbound and inbound traffic bridgeOptions = new BridgeOptions(); bridgeOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(".*")); bridgeOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(".*")); // sockJsHandler = SockJSHandler.create(vertx).bridge(bridgeOptions); sockJsHandler = SockJSHandler.create(vertx); sockJsHandler.bridge(bridgeOptions, be -> { try { if (be.type() == BridgeEventType.SOCKET_CREATED) { handleSocketOpenEvent(be); } else if (be.type() == BridgeEventType.REGISTER) { handleRegisterEvent(be); } else if (be.type() == BridgeEventType.UNREGISTER) { handleUnregisterEvent(be); } else if (be.type() == BridgeEventType.SOCKET_CLOSED) { handleSocketCloseEvent(be); } } catch (Exception e) { } finally { be.complete(true); } }); router.route("/eventbus/*").handler(sockJsHandler); if (testPathEnabled) { router.route("/" + testUrlPath + "/*") .handler(StaticHandler.create(testFilePath).setCachingEnabled(cachingEnabled)); } // create periodic task, pushing all current EventBusRegistrations vertx.setPeriodic(1000, handler -> { JsonObject obj = new JsonObject(); obj.put("testMessage", "Periodic test message from server..."); vertx.eventBus().publish("heartbeat-test", Json.encodePrettily(obj)); }); EventBus eb = vertx.eventBus(); eb.consumer("client-test", message -> { log.info("Received message from client: " + Json.encodePrettily(message.body()) + " at " + System.currentTimeMillis()); }); HttpServerOptions httpOptions = new HttpServerOptions(); if (sslEnabled) { httpOptions.setSsl(true); httpOptions.setKeyStoreOptions(sslKeyStoreOptions); } log.info("starting web server on port: " + port); vertx.createHttpServer(httpOptions).requestHandler(router::accept).listen(port, result -> { if (result.succeeded()) { setStarted(true); log.info("Server started and ready to accept requests"); fut.complete(); } else { setStarted(false); fut.fail(result.cause()); } }); }
From source file:studio.lysid.scales.facade.FacadeVerticle.java
License:Open Source License
private void bindClientStaticResources() { this.router.route(HttpMethod.GET, "/*").handler(StaticHandler.create("public")); }
From source file:studio.lysid.scales.facade.FacadeVerticle.java
License:Open Source License
private void bindQueryServices() { QueryScaleService queryScaleService = eventBusServiceHelper.getProxy(QueryScaleService.class, Service.QueryScale.address); router.route(HttpMethod.GET, "/scale/:id").handler(routingContext -> { HttpServerResponse response = routingContext.response(); logger.info("Request received: " + routingContext.request().uri()); int id = Integer.parseInt(routingContext.request().getParam("id")); response.putHeader("content-type", "text/html"); queryScaleService.findScaleById(id, ar -> { if (ar.succeeded()) { response.end(ar.result().encodePrettily()); } else { response.setStatusCode(404).end("Scale #" + id + " does not exist!"); }//from w ww . ja v a 2s .c om }); }); }