List of usage examples for io.vertx.core.http HttpMethod OPTIONS
HttpMethod OPTIONS
To view the source code for io.vertx.core.http HttpMethod OPTIONS.
Click Source Link
From source file:Console.java
@Override public void start(Future<Void> fut) { HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); // router.route("/static/*").handler(StaticHandler. // create() // .setWebRoot("C:/Users/User/Documents/bekUP/ArduinoOnlineIDE/resources") // .setCachingEnabled(false) // .setAllowRootFileSystemAccess(true) // .setDirectoryListing(true) // .setMaxAgeSeconds(1000) // );/*from w w w. j a v a 2 s .c om*/ router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.OPTIONS).allowedHeader("X-PINGARUNER").allowedHeader("Content-Type")); DbHelper.getInstance().init(vertx); FileAccess.getInstance().init(vertx); router.get("/project/openProject/:projectId").handler(this::handleOpenProject); router.get("/project/loadFile/:projectId/:fileId").handler(this::handleLoadFile); router.post("/project/create").handler(this::handleCreateProject); router.post("/project/saveFile/:projectId/:fileId").handler(this::handleSaveFile); router.get("/project/getListProject").handler(this::handleGetListProject); router.post("/project/updateProjectConfig/:fileId").handler(this::testing); router.get("/project/downloadHex/:projectId").handler(this::testing); router.get("/project/createFile/:projectId/:directory/:fileName").handler(this::handleCreateFile); router.get("/project/createFolder/:projectId/:directory/:folderName").handler(this::handleCreateFolder); server.requestHandler(router::accept).listen(8080); }
From source file:com.atypon.wayf.verticle.WayfVerticle.java
License:Apache License
private void startWebApp(Handler<AsyncResult<HttpServer>> next) { Guice.createInjector(new WayfGuiceModule()).injectMembers(this); routingProviders = Lists.newArrayList(identityProviderUsageRouting, identityProviderRouting, deviceRoutingProvider, publisherRouting, deviceAccessRouting, publisherRegistrationRouting, userRouting);//from www .ja v a2 s .co m // Create a router object. Router router = Router.router(vertx); CorsHandler handler = CorsHandler.create("*").allowCredentials(true) .allowedMethod(io.vertx.core.http.HttpMethod.PATCH) .allowedMethod(io.vertx.core.http.HttpMethod.OPTIONS) .allowedMethod(io.vertx.core.http.HttpMethod.DELETE).exposedHeaders(Sets.newHashSet("X-Device-Id")) .allowedHeader("Access-Control-Request-Method") .allowedHeader("Access-Control-Allow-AuthenticationCredentials") .allowedHeader("Access-Control-Allow-Origin").allowedHeader("Access-Control-Allow-Headers") .allowedHeader("Content-Type").allowedHeader("Authorization"); router.route().handler(handler); router.route().handler(CookieHandler.create()); LOG.debug("Adding routes"); routingProviders.forEach((routingProvider) -> routingProvider.addRoutings(router)); LOG.debug("Adding default error handler to routes"); for (Route route : router.getRoutes()) { route.failureHandler((rc) -> responseWriter.buildFailure(rc)); LOG.debug("Found path {}", route); } router.route("/public/*").handler(StaticHandler.create("public")); LOG.debug("Starting HTTP server"); // Create the HTTP server and pass the "accept" method to the request handler. vertx.createHttpServer().requestHandler(router::accept).listen(wayfPort, next::handle); }
From source file:com.company.vertxstarter.MainVerticle.java
@Override public void start(Future<Void> fut) { // Create a router object. Router router = Router.router(vertx); //CORS handler router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.OPTIONS).allowedHeader("Content-Type").allowedHeader("Accept")); //default headers router.route().handler(ctx -> {/* www. j ava 2 s . com*/ ctx.response().putHeader("Cache-Control", "no-store, no-cache").putHeader("Content-Type", "application/json"); if (StringUtils.isEmpty(ctx.request().getHeader("Accept"))) { ctx.fail(Failure.NO_MEDIA_TYPE); return; } else if (!"application/json".equalsIgnoreCase(ctx.request().getHeader("Accept"))) { ctx.fail(Failure.UNSUPPORTED_MEDIA_TYPE); return; } ctx.next(); }); //error handling router.route().failureHandler(ctx -> { HttpServerResponse response = ctx.response(); final JsonObject error = new JsonObject(); Failure ex; if (ctx.failure() instanceof Failure) { //specific error ex = (Failure) ctx.failure(); } else { //general error ctx.failure().printStackTrace(); ex = Failure.INTERNAL_ERROR; } error.put("message", ex.getMessage()); response.setStatusCode(ex.getCode()).end(error.encode()); }); //default 404 handling router.route().last().handler(ctx -> { HttpServerResponse response = ctx.response(); final JsonObject error = new JsonObject(); error.put("message", Failure.NOT_FOUND.getMessage()); response.setStatusCode(404).end(error.encode()); }); //routes Injector injector = Guice.createInjector(new AppInjector()); router.route(HttpMethod.GET, "/people").handler(injector.getInstance(PersonResource.class)::get); // Create the HTTP server and pass the "accept" method to the request handler. HttpServerOptions serverOptions = new HttpServerOptions(); serverOptions.setCompressionSupported(true); vertx.createHttpServer(serverOptions).requestHandler(router::accept) .listen(config().getInteger("http.port", 8080), result -> { if (result.succeeded()) { fut.complete(); } else { fut.fail(result.cause()); } }); }
From source file:com.ddp.SimpleREST.java
License:Open Source License
@Override public void start() { setUpInitialData();/*from ww w .j a va2 s.c om*/ Router router = Router.router(vertx); router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.OPTIONS).allowedHeader("X-PINGARUNER").allowedHeader("Content-Type")); //router.route().handler(BodyHandler.create()); router.get("/hierarchy").handler(this::getListHierarchy); router.post("/hierarchy").handler(this::postHierarchy); router.post("/runner").handler(this::postSparkRunner); router.get("/hiveHierarchy").handler(this::getHiveHierarchy); router.post("/postJars").handler(BodyHandler.create().setUploadsDirectory(localUploadHome)); router.post("/postJars").handler(this::postJars); router.post("/postScalaFiles").handler(BodyHandler.create().setUploadsDirectory(localUploadHome)); router.post("/postScalaFiles").handler(this::postScalaFiles); router.post("/postSampleFiles").handler(BodyHandler.create().setUploadsDirectory(localUploadHome)); router.post("/postSampleFiles").handler(this::postSampleFiles); router.post("/userFunctionHierarchy").handler(this::postUserFunctionHierarchy); router.get("/userFunctionHierarchy").handler(this::getUserFunctionHierarchy); router.get("/userFunctionCompile").handler(this::getUserFunctionCompile); vertx.createHttpServer().requestHandler(router::accept).listen(httpPort); eventBus = getVertx().eventBus(); eventBus.registerDefaultCodec(BaseRequest.class, new BaseRequestCodec()); }
From source file:com.deblox.server.MockServer.java
License:Apache License
@Override public void start(Future<Void> startFuture) { logger.info("starting with config: " + config().toString()); Router router = Router.router(vertx); try {/* w w w . j av a2s . c o m*/ serverConfig = Util.loadConfig(config().getString("serverConfig", "/conf.json")).getJsonObject( config().getString("serverVerticle", "com.deblox.solacemonitor.MonitorVerticle")); metrics = serverConfig.getJsonObject("config").getJsonObject("metrics"); logger.info("metrics: " + metrics); } catch (IOException e) { e.printStackTrace(); } router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.OPTIONS).allowedHeader("Content-Type")); router.get("/SEMP").handler(ctx -> { logger.debug("mock server taking request"); ctx.response().setChunked(true); ctx.response().write("POST YOUR SEMP REQUESTS HERE"); ctx.response().end(); }); /* accepts XML posted to /SEMP, matches XML against metrics's request string in serverConfig's metrics object reads a XML file from resources matching the NAME of the metric e.g. stats */ router.post("/SEMP").handler(ctx -> { logger.debug("mock server taking request"); for (Map.Entry<String, String> entry : ctx.request().headers()) { logger.debug("Header: " + entry.getKey() + " : " + entry.getValue()); } ctx.request().bodyHandler(body -> { logger.debug("Body Handler"); logger.debug(body.toString()); logger.debug("Matching metrics:"); metrics.forEach(e -> { logger.debug(e.getKey()); JsonObject j = (JsonObject) e.getValue(); try { if (j.getString("request").equals(body.toString())) { logger.debug("MATCHED"); ctx.response().setChunked(true); try { ctx.response().sendFile("mock/" + e.getKey() + ".xml"); } catch (Exception x) { x.printStackTrace(); } } } catch (Exception x) { logger.warn("skipping " + j.toString()); } logger.debug(j.getString("request")); }); }); }); // the server itself vertx.createHttpServer().requestHandler(router::accept).listen(config().getInteger("port", 8081)); // send back deployment complete startFuture.complete(); }
From source file:com.waves_rsp.ikb4stream.communication.web.VertxServer.java
License:Open Source License
/** * Server starting behaviour//from www. j a v a2 s .c o m * * @param fut Future that handles the start status * @throws NullPointerException if fut is null */ @Override public void start(Future<Void> fut) { Objects.requireNonNull(fut); Router router = Router.router(vertx); router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.OPTIONS).allowedHeader("X-PINGARUNER").allowedHeader("Content-Type")); router.route("/anomaly*").handler(BodyHandler.create()); // enable reading of request's body router.get("/anomaly").handler(this::getAnomalies); router.post("/anomaly").handler(this::getAnomalies); vertx.createHttpServer().requestHandler(router::accept).listen(config().getInteger("http.port", 8081), // default value: 8081 result -> { if (result.succeeded()) { fut.complete(); } else { fut.fail(result.cause()); } }); LOGGER.info("VertxServer started"); }
From source file:es.upv.grycap.opengateway.core.http.BaseRestService.java
License:Apache License
@Override public void start() throws Exception { requireNonNull(serviceConfig, "A valid service configuration expected"); requireNonNull(loadBalancerClient, "A valid load balancer client expected"); // set body limit and create router final long maxBodySize = context.config().getLong("http-server.max-body-size", MAX_BODY_SIZE_MIB) * 1024l * 1024l;/*from ww w . j ava2s.c o m*/ final Router router = Router.router(vertx); router.route().handler(BodyHandler.create().setBodyLimit(maxBodySize)); // enable CORS router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.PUT).allowedMethod(HttpMethod.DELETE).allowedMethod(HttpMethod.OPTIONS) .allowedHeader("Content-Type").allowedHeader("Authorization")); // configure index page router.route(serviceConfig.getFrontpage().orElse("/")).handler(StaticHandler.create()); // serve resources serviceConfig.getServices().values().stream().forEach(s -> { final String path = requireNonNull(s.getPath(), "A valid path required"); router.get(String.format("%s/:id", path)).produces("application/json").handler(e -> handleGet(s, e)); router.get(path).produces("application/json").handler(e -> handleList(s, e)); router.post(path).handler(e -> handleCreate(s, e)); router.put(String.format("%s/:id", path)).consumes("application/json").handler(e -> handleModify(s, e)); router.delete(String.format("%s/:id", path)).handler(e -> handleDelete(s, e)); }); // start HTTP server final int port = context.config().getInteger("http.port", 8080); vertx.createHttpServer().requestHandler(router::accept).listen(port); logger.trace("New instance created: [id=" + context.deploymentID() + "]."); }
From source file:io.gravitee.gateway.http.vertx.VertxHttpClient.java
License:Apache License
private HttpMethod convert(io.gravitee.common.http.HttpMethod httpMethod) { switch (httpMethod) { case CONNECT: return HttpMethod.CONNECT; case DELETE:/*from w w w .ja v a 2 s. com*/ return HttpMethod.DELETE; case GET: return HttpMethod.GET; case HEAD: return HttpMethod.HEAD; case OPTIONS: return HttpMethod.OPTIONS; case PATCH: return HttpMethod.PATCH; case POST: return HttpMethod.POST; case PUT: return HttpMethod.PUT; case TRACE: return HttpMethod.TRACE; } return null; }
From source file:org.eclipse.hono.adapter.http.HonoAuthHandlerImpl.java
License:Open Source License
private boolean handlePreflight(RoutingContext ctx) { final HttpServerRequest request = ctx.request(); // See: https://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0 // Preflight requests should not be subject to security due to the reason UAs will remove the Authorization header if (request.method() == HttpMethod.OPTIONS) { // check if there is a access control request header final String accessControlRequestHeader = ctx.request() .getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS); if (accessControlRequestHeader != null) { // lookup for the Authorization header for (String ctrlReq : accessControlRequestHeader.split(",")) { if (ctrlReq.equalsIgnoreCase("Authorization")) { // this request has auth in access control, so we can allow preflighs without authentication ctx.next();/*from w ww . j a v a2s . c om*/ return true; } } } } return false; }
From source file:org.eclipse.hono.service.auth.device.HonoAuthHandler.java
License:Open Source License
private boolean handlePreflight(final RoutingContext ctx) { final HttpServerRequest request = ctx.request(); // See: https://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0 // Preflight requests should not be subject to security due to the reason UAs will remove the Authorization header if (request.method() == HttpMethod.OPTIONS) { // check if there is a access control request header final String accessControlRequestHeader = ctx.request() .getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS); if (accessControlRequestHeader != null) { // lookup for the Authorization header for (final String ctrlReq : accessControlRequestHeader.split(",")) { if (ctrlReq.equalsIgnoreCase("Authorization")) { // this request has auth in access control, so we can allow preflighs without authentication ctx.next();/*from w w w . java2s .c om*/ return true; } } } } return false; }