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:com.hubrick.vertx.rest.rx.impl.DefaultRxRestClient.java
License:Apache License
@Override public Observable<RestClientResponse<Void>> get(String uri, Action1<RestClientRequest> requestBuilder) { return request(HttpMethod.GET, uri, Void.class, requestBuilder); }
From source file:com.hubrick.vertx.rest.rx.impl.DefaultRxRestClient.java
License:Apache License
@Override public <T> Observable<RestClientResponse<T>> get(String uri, Class<T> responseClass, Action1<RestClientRequest> requestBuilder) { return request(HttpMethod.GET, uri, responseClass, requestBuilder); }
From source file:com.klwork.spring.vertx.render.MyStaticHandlerImpl.java
License:Open Source License
@Override public void handle(RoutingContext context) { HttpServerRequest request = context.request(); if (request.method() != HttpMethod.GET && request.method() != HttpMethod.HEAD) { if (log.isTraceEnabled()) log.trace("Not GET or HEAD so ignoring request"); context.next();/*from w w w. j a va 2 s . c om*/ } else { String path = context.normalisedPath(); // if the normalized path is null it cannot be resolved if (path == null) { log.warn("Invalid path: " + context.request().path() + " so returning 404"); context.fail(NOT_FOUND.code()); return; } // only root is known for sure to be a directory. all other directories must be identified as such. if (!directoryListing && "/".equals(path)) { path = indexPage; } // can be called recursive for index pages sendStatic(context, path); } }
From source file:com.redhat.developers.helloworld.HelloworldVerticle.java
License:Apache License
@Override public void start() throws Exception { Router router = Router.router(vertx); //Config CORS router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedHeader("Content-Type")); // hello endpoint router.get("/api/hello/:name").handler(ctx -> { ctx.response().end(hello(ctx.request().getParam("name"))); });//from www .j av a 2 s .c o m vertx.createHttpServer().requestHandler(router::accept).listen(8080); }
From source file:com.redhat.developers.msa.aloha.AlohaVerticle.java
License:Apache License
@Override public void start() throws Exception { Router router = Router.router(vertx); router.route().handler(ctx -> {// w w w . java 2 s . co m // note: this is *not* an example of how to properly integrate vert.x with zipkin // for a more appropriate way to do that, check the vert.x documentation ServerRequestInterceptor serverRequestInterceptor = BRAVE.serverRequestInterceptor(); serverRequestInterceptor.handle(new HttpServerRequestAdapter(new VertxHttpServerRequest(ctx.request()), new DefaultSpanNameProvider())); ctx.data().put("zipkin.span", BRAVE.serverSpanThreadBinder().getCurrentServerSpan()); ctx.next(); ctx.addBodyEndHandler(v -> BRAVE.serverResponseInterceptor() .handle(new HttpServerResponseAdapter(() -> ctx.response().getStatusCode()))); }); router.route().handler(BodyHandler.create()); router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET).allowedHeader("Content-Type")); // Aloha EndPoint router.get("/api/aloha").handler(ctx -> ctx.response().end(aloha())); // Aloha Chained Endpoint router.get("/api/aloha-chaining").handler(ctx -> alohaChaining(ctx, (list) -> ctx.response().putHeader("Content-Type", "application/json").end(Json.encode(list)))); // Health Check router.get("/api/health").handler(ctx -> ctx.response().end("I'm ok")); // Hysrix Stream Endpoint router.get(EventMetricsStreamHandler.DEFAULT_HYSTRIX_PREFIX) .handler(EventMetricsStreamHandler.createHandler()); // Static content router.route("/*").handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router::accept).listen(8080); System.out.println("Service running at 0.0.0.0:8080"); }
From source file:com.waves_rsp.ikb4stream.communication.web.VertxServer.java
License:Open Source License
/** * Server starting behaviour//from w w w .j a v a 2 s. co 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:de.braintags.netrelay.controller.api.MailController.java
License:Open Source License
private static void readData(MailPreferences prefs, UriMailAttachment attachment, Handler<AsyncResult<Void>> handler) { URI uri = attachment.getUri(); HttpClient client = prefs.httpClient; int port = uri.getPort() > 0 ? uri.getPort() : 80; HttpClientRequest req = client.request(HttpMethod.GET, port, uri.getHost(), uri.getPath(), resp -> { resp.bodyHandler(buff -> {/* w w w . j av a 2 s. c o m*/ try { attachment.setData(buff); handler.handle(Future.succeededFuture()); } catch (Exception e) { LOGGER.error("", e); handler.handle(Future.failedFuture(e)); } }); }); req.end(); }
From source file:de.elsibay.EbbTicketShowcase.java
License:Open Source License
@Override public void start(Future<Void> startFuture) throws Exception { SessionStore sessionStore = LocalSessionStore.create(vertx); Router backendRouter = Router.router(vertx); backendRouter.route().handler(LoggerHandler.create(LoggerHandler.DEFAULT_FORMAT)); CookieHandler cookieHandler = CookieHandler.create(); SessionHandler sessionHandler = SessionHandler.create(sessionStore); // the CORS OPTION request must not set cookies backendRouter.get().handler(cookieHandler); backendRouter.get().handler(sessionHandler); backendRouter.post().handler(cookieHandler); backendRouter.post().handler(sessionHandler); // setup CORS CorsHandler corsHandler = CorsHandler.create("http(s)?://" + WEBSERVER_HOST + ":" + WEBSERVER_PORT) .allowCredentials(true).allowedHeader(HttpHeaders.ACCEPT.toString()) .allowedHeader(HttpHeaders.ORIGIN.toString()).allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()).allowedHeader(HttpHeaders.COOKIE.toString()) .exposedHeader(HttpHeaders.SET_COOKIE.toString()).allowedMethod(HttpMethod.POST) .allowedMethod(HttpMethod.PUT).allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.DELETE); // setup event bus bridge TicketEventbusBridge sebb = new TicketEventbusBridge(sessionStore); backendRouter.mountSubRouter("/eventbus", sebb.route(vertx)); // dummy eventbus services vertx.eventBus().consumer("ping", (Message<JsonObject> msg) -> { msg.reply(new JsonObject().put("answer", "pong " + msg.body().getString("text", ""))); });//w w w. j a v a 2 s .c o m vertx.setPeriodic(5000, id -> { vertx.eventBus().send("topic", new JsonObject().put("timestamp", new Date().getTime())); }); // session manager for login backendRouter.route("/api/*").handler(corsHandler); backendRouter.route("/api/*").method(HttpMethod.POST).method(HttpMethod.PUT).handler(BodyHandler.create()); backendRouter.route("/api/session").handler((RoutingContext rc) -> { JsonObject user = rc.getBodyAsJson(); String sessionId = rc.session().id(); rc.session().put("user", user); rc.response().end(user.copy().put("sessionId", sessionId).encodePrettily()); }); // dummy ping REST service backendRouter.route("/api/ping").handler((RoutingContext rc) -> { JsonObject replyMsg = new JsonObject(); replyMsg.put("timestamp", new Date().getTime()); Cookie sessionCookie = rc.getCookie(SessionHandler.DEFAULT_SESSION_COOKIE_NAME); if (sessionCookie != null) { replyMsg.put("sessionId", sessionCookie.getValue()); } rc.response().end(replyMsg.encode()); }); // start backend on one port vertx.createHttpServer().requestHandler(backendRouter::accept).listen(BACKENDSERVER_PORT, BACKENDSERVER_HOST, (AsyncResult<HttpServer> async) -> { System.out .println(async.succeeded() ? "Backend Server started" : "Backend Server start FAILED"); }); // static files on other port Router staticFilesRouter = Router.router(vertx); staticFilesRouter.route("/*").handler(StaticHandler.create("src/main/www").setCachingEnabled(false)); vertx.createHttpServer().requestHandler(staticFilesRouter::accept).listen(WEBSERVER_PORT, WEBSERVER_HOST, (AsyncResult<HttpServer> async) -> { System.out.println(async.succeeded() ? "Web Server started\ngoto http://" + WEBSERVER_HOST + ":" + WEBSERVER_PORT + "/" : "Web Server start FAILED"); }); }
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 w ww.j a v a2 s . 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:examples.AuthOAuth2Examples.java
License:Open Source License
public void example3(Vertx vertx) { // Initialize the OAuth2 Library OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.PASSWORD); JsonObject tokenConfig = new JsonObject().put("username", "username").put("password", "password"); // Callbacks/* www .ja va2s. c o m*/ // Save the access token oauth2.getToken(tokenConfig, res -> { if (res.failed()) { System.err.println("Access Token Error: " + res.cause().getMessage()); } else { // Get the access token object (the authorization code is given from the previous step). AccessToken token = res.result(); oauth2.api(HttpMethod.GET, "/users", new JsonObject().put("access_token", token.principal().getString("access_token")), res2 -> { // the user object should be returned here... }); } }); }