List of usage examples for io.vertx.core.http HttpMethod POST
HttpMethod POST
To view the source code for io.vertx.core.http HttpMethod POST.
Click Source Link
From source file:io.servicecomb.serviceregistry.client.http.RestUtils.java
License:Apache License
public static void post(IpPort ipPort, String uri, RequestParam requestParam, Handler<RestResponse> responseHandler) { httpDo(createRequestContext(HttpMethod.POST, ipPort, uri, requestParam), responseHandler); }
From source file:io.ventu.rpc.rest.HttpRestInvokerImpl.java
License:MIT License
@Override public <RQ, RS> CompletableFuture<RS> invoke(final RQ request, final Class<RS> responseClass) { final CompletableFuture<RS> answer = new CompletableFuture<>(); try {/*www . j ava 2 s . com*/ String url = requestRouter.route(request); HttpMethod method = HttpMethod.POST; switch (requestRouter.type(request)) { case GET: method = HttpMethod.GET; break; case PUT: method = HttpMethod.PUT; break; case DELETE: method = HttpMethod.DELETE; break; default: // POST, keep as is } HttpClientRequest httpRequest = client.request(method, url, httpResponse -> { int statusCode = httpResponse.statusCode(); if (statusCode < 400) { httpResponse.bodyHandler(buffer -> { try { RS resp = serializer.decode(buffer.getBytes(), responseClass); responseValidator.validate(resp); answer.complete(resp); } catch (ApiException | EncodingException | IllegalArgumentException | NullPointerException ex) { answer.completeExceptionally(ex); } }); } else { answer.completeExceptionally(new HttpException(statusCode, httpResponse.statusMessage())); } }); for (Entry<String, String> entry : headers.entrySet()) { httpRequest.putHeader(entry.getKey(), entry.getValue()); } httpRequest.putHeader("Content-type", CONTENT_TYPE).putHeader("Accept", CONTENT_TYPE); if ((method == HttpMethod.POST) || (method == HttpMethod.PUT)) { byte[] payload = serializer.encode(request); httpRequest.setChunked(true).end(Buffer.buffer(payload)); } else { httpRequest.end(); } } catch (IllegalArgumentException | EncodingException ex) { answer.completeExceptionally(ex); } return answer; }
From source file:microservices.MessageService.java
@Override public void start() { Router router = Router.router(vertx); //testa om servicen fungerar router.route("/").handler(routingContext -> { HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "text/html") .end("<h1>Hello from my first Vert.x 3 application</h1>"); });/* w w w . j a va 2 s .c o m*/ //skapa bodyhandler fr att kunna lsa body i requests router.route(HttpMethod.POST, "/*").handler(BodyHandler.create()); router.post("/api/createnewmessage").handler(this::createnewmessage); router.get("/api/messages/:user").handler(this::getmessages); //router.post("/api/createnewpost").handler(this::createnewpost); //router.get("/api/posts/:user").handler(this::getposts); vertx.createHttpServer().requestHandler(router::accept).listen(1124); System.out.println("Messages service started"); }
From source file:microservices.PostService.java
@Override public void start() { Router router = Router.router(vertx); //testa om servicen fungerar router.route("/").handler(routingContext -> { HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "text/html") .end("<h1>Hello from my first Vert.x 3 application</h1>"); });/* www .j a va2s. c om*/ //skapa bodyhandler fr att kunna lsa body i requests router.route(HttpMethod.POST, "/*").handler(BodyHandler.create()); router.post("/api/createnewpost").handler(this::createnewpost); router.get("/api/posts/:user").handler(this::getposts); vertx.createHttpServer().requestHandler(router::accept).listen(1123); System.out.println("Posts service started"); }
From source file:microservices.UserService.java
@Override public void start() { Router router = Router.router(vertx); //testa om servicen fungerar router.route("/").handler(routingContext -> { HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "text/html") .end("<h1>Hello from my first Vert.x 3 application</h1>"); });//w ww . j av a 2s .c om //skapa bodyhandler fr att kunna lsa body i requests router.route(HttpMethod.POST, "/*").handler(BodyHandler.create()); router.post("/api/checkalreadyexists").handler(this::checkalreadyexists); router.get("/api/user").handler(this::getAllUsers); router.get("/api/images/:user").handler(this::getUserImages); router.post("/api/login").handler(this::login); router.post("/api/createuser").handler(this::createuser); router.post("/api/savediagram").handler(this::saveDiagram); vertx.createHttpServer().requestHandler(router::accept).listen(1122); System.out.println("User service started"); }
From source file:org.azrul.langmera.DecisionService.java
@Override public void start(Future<Void> fut) { // Create a router object. Router router = Router.router(vertx); //enable CORS if (config.getProperty("enableCors", Boolean.class)) { String allowedAddress = config.getProperty("cors.allowedAddress", String.class); CorsHandler c = CorsHandler.create(allowedAddress); String allowedHeaders = config.getProperty("cors.allowedHeaders", String.class); if (allowedHeaders != null) { String[] allowedHeadersArray = allowedHeaders.split(","); c.allowedHeaders(new HashSet<String>(Arrays.asList(allowedHeadersArray))); }//from w w w. j a va 2 s. c o m String allowedMethods = config.getProperty("cors.allowedMethods", String.class); if (allowedMethods != null) { String[] allowedMethodsArray = allowedMethods.split(","); for (String m : allowedMethodsArray) { if ("POST".equals(m)) { c.allowedMethod(HttpMethod.POST); } else if ("PUT".equals(m)) { c.allowedMethod(HttpMethod.PUT); } else if ("GET".equals(m)) { c.allowedMethod(HttpMethod.GET); } else if ("DELETE".equals(m)) { c.allowedMethod(HttpMethod.DELETE); } } } router.route().handler(c); } //Handle body router.route().handler(BodyHandler.create()); //router.route("/langmera/assets/*").handler(StaticHandler.create("assets")); router.post("/langmera/api/makeDecision").handler(this::makeDecision); router.post("/langmera/api/acceptFeedback").handler(this::acceptFeedback); //router.post("/langmera/api/getHistory").handler(this::getHistory); //router.post("/langmera/api/getRequestTemplate").handler(this::getRequestTemplate); //router.post("/langmera/api/getResponseTemplate").handler(this::getFeedbackTemplate); HttpServerOptions options = new HttpServerOptions(); options.setReuseAddress(true); // Create the HTTP server and pass the "accept" method to the request handler. vertx.createHttpServer(options).requestHandler(router::accept).listen( // Retrieve the port from the configuration, // default to 8080. config().getInteger("http.port", config.getProperty("http.port", Integer.class)), result -> { if (result.succeeded()) { fut.complete(); } else { fut.fail(result.cause()); } }); }
From source file:org.eclipse.hono.adapter.http.vertx.VertxBasedHttpProtocolAdapter.java
License:Open Source License
private void addTelemetryApiRoutes(final Router router, final Handler<RoutingContext> authHandler) { // support CORS headers for PUTing telemetry router.routeWithRegex("\\/telemetry\\/[^\\/]+\\/.*") .handler(CorsHandler.create(getConfig().getCorsAllowedOrigin()).allowedMethod(HttpMethod.PUT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); if (getConfig().isAuthenticationRequired()) { // support CORS headers for POSTing telemetry router.route("/telemetry") .handler(CorsHandler.create(getConfig().getCorsAllowedOrigin()).allowedMethod(HttpMethod.POST) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); // require auth for POSTing telemetry router.route(HttpMethod.POST, "/telemetry").handler(authHandler); // route for posting telemetry data using tenant and device ID determined as part of // device authentication router.route(HttpMethod.POST, "/telemetry").handler(this::handlePostTelemetry); // require auth for PUTing telemetry router.route(HttpMethod.PUT, "/telemetry/*").handler(authHandler); // assert that authenticated device's tenant matches tenant from path variables router.route(HttpMethod.PUT, String.format("/telemetry/:%s/:%s", PARAM_TENANT, PARAM_DEVICE_ID)) .handler(this::assertTenant); }/* w w w. j av a 2s .co m*/ // route for uploading telemetry data router.route(HttpMethod.PUT, String.format("/telemetry/:%s/:%s", PARAM_TENANT, PARAM_DEVICE_ID)) .handler(ctx -> uploadTelemetryMessage(ctx, getTenantParam(ctx), getDeviceIdParam(ctx))); }
From source file:org.eclipse.hono.adapter.http.vertx.VertxBasedHttpProtocolAdapter.java
License:Open Source License
private void addEventApiRoutes(final Router router, final Handler<RoutingContext> authHandler) { // support CORS headers for PUTing events router.routeWithRegex("\\/event\\/[^\\/]+\\/.*") .handler(CorsHandler.create(getConfig().getCorsAllowedOrigin()).allowedMethod(HttpMethod.PUT) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); if (getConfig().isAuthenticationRequired()) { // support CORS headers for POSTing events router.route("/event") .handler(CorsHandler.create(getConfig().getCorsAllowedOrigin()).allowedMethod(HttpMethod.POST) .allowedHeader(HttpHeaders.AUTHORIZATION.toString()) .allowedHeader(HttpHeaders.CONTENT_TYPE.toString())); // require auth for POSTing events router.route(HttpMethod.POST, "/event").handler(authHandler); // route for posting events using tenant and device ID determined as part of // device authentication router.route(HttpMethod.POST, "/event").handler(this::handlePostEvent); // require auth for PUTing events router.route(HttpMethod.PUT, "/event/*").handler(authHandler); // route for asserting that authenticated device's tenant matches tenant from path variables router.route(HttpMethod.PUT, String.format("/event/:%s/:%s", PARAM_TENANT, PARAM_DEVICE_ID)) .handler(this::assertTenant); }/*from w w w .j a va 2 s.c om*/ // route for sending event messages router.route(HttpMethod.PUT, String.format("/event/:%s/:%s", PARAM_TENANT, PARAM_DEVICE_ID)) .handler(ctx -> uploadEventMessage(ctx, getTenantParam(ctx), getDeviceIdParam(ctx))); }
From source file:org.eclipse.hono.service.registration.RegistrationHttpEndpoint.java
License:Open Source License
@Override public void addRoutes(final Router router) { final String pathWithTenant = String.format("/%s/:%s", RegistrationConstants.REGISTRATION_ENDPOINT, PARAM_TENANT_ID);/*from ww w .j a v a2 s .co m*/ // ADD device registration router.route(HttpMethod.POST, pathWithTenant).consumes(HttpEndpointUtils.CONTENT_TYPE_JSON) .handler(this::doRegisterDeviceJson); router.route(HttpMethod.POST, pathWithTenant) .consumes(HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED.toString()) .handler(this::doRegisterDeviceForm); router.route(HttpMethod.POST, pathWithTenant).handler( ctx -> HttpEndpointUtils.badRequest(ctx.response(), "missing or unsupported content-type")); final String pathWithTenantAndDeviceId = String.format("/%s/:%s/:%s", RegistrationConstants.REGISTRATION_ENDPOINT, PARAM_TENANT_ID, PARAM_DEVICE_ID); // GET device registration router.route(HttpMethod.GET, pathWithTenantAndDeviceId).handler(this::doGetDevice); // UPDATE existing registration router.route(HttpMethod.PUT, pathWithTenantAndDeviceId).consumes(HttpEndpointUtils.CONTENT_TYPE_JSON) .handler(this::doUpdateRegistrationJson); router.route(HttpMethod.PUT, pathWithTenantAndDeviceId) .consumes(HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED.toString()) .handler(this::doUpdateRegistrationForm); router.route(HttpMethod.PUT, pathWithTenantAndDeviceId).handler( ctx -> HttpEndpointUtils.badRequest(ctx.response(), "missing or unsupported content-type")); // REMOVE registration router.route(HttpMethod.DELETE, pathWithTenantAndDeviceId).handler(this::doUnregisterDevice); }
From source file:org.etourdot.vertx.marklogic.http.impl.request.DefaultMarklogicRequest.java
License:Open Source License
@Override public MarkLogicRequest post(String uri) { return method(uri, HttpMethod.POST); }