@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end("{\"message\":\"Hello World\"}"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end("{\"message\":\"Hello World\"}"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>"); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>"); }); server.listen(8080); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); router.route().handler(routingContext -> { routingContext.response().putHeader("content-type", "text/html").end("Hello World!"); }); vertx.createHttpServer().requestHandler(router).listen(8080); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.route().handler(req -> req.response().putHeader("content-type", "text/html") .end("<html><body><h1>Hello from vert.x!</h1></body></html>")); HttpServer server = vertx.createHttpServer(); server.requestStream() .toFlowable() .map(HttpServerRequest::pause) .onBackpressureDrop(req -> req.response().setStatusCode(503).end()) .observeOn(RxHelper.scheduler(vertx.getDelegate())) .subscribe(req -> { req.resume(); router.accept(req); }); server.rxListen(PORT).subscribe(res -> generateRequests()); }
/** * Send back a response with status 200 Ok. * * @param context routing context */ protected void ok(RoutingContext context) { context.response().end(); }
/** * Send back a response with status 204 No Content. * * @param context routing context */ protected void noContent(RoutingContext context) { context.response().setStatusCode(204).end(); }
/** * Send back a response with status 503 Service Unavailable. * * @param context routing context * @param ex exception */ protected void serviceUnavailable(RoutingContext context, Throwable ex) { context.response().setStatusCode(503) .putHeader("content-type", "application/json") .end(new JsonObject().put("error", ex.getMessage()).encodePrettily()); }
/** * Send back a response with status 500 Internal Error. * * @param context routing context * @param ex exception */ protected void internalError(RoutingContext context, Throwable ex) { context.response().setStatusCode(500) .putHeader("content-type", "application/json") .end(new JsonObject().put("error", ex.getMessage()).encodePrettily()); }
/** * Send back a response with status 404 Not Found. * * @param context routing context */ protected void notFound(RoutingContext context) { context.response().setStatusCode(404) .putHeader("content-type", "application/json") .end(new JsonObject().put("message", "not_found").encodePrettily()); }
/** * Send back a response with status 201 Created. * * @param context routing context * @param content body content in JSON format */ protected void created(RoutingContext context, String content) { context.response().setStatusCode(201) .putHeader("content-type", "application/json") .end(content); }
@Override public void handle(RoutingContext context) { jwkSetService.getKeys().subscribe(keys -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, "application/jwk-set+json; charset=UTF-8") .end(Json.encodePrettily(keys)), error -> context.response().setStatusCode(500).end()); }
private void sendResponse(final RoutingContext context, final ClientResponse clientResponse) { HttpServerResponse httpResponse = context.response(); writeHeaders(context.response(), clientResponse); httpResponse.setStatusCode(clientResponse.getStatusCode()); if (isOkClientResponse(clientResponse)) { httpResponse.end(Buffer.newInstance(clientResponse.getBody())); } else { httpResponse.end(); } }
private void sendNotFound(HttpServerResponse serverResponse) { // Send a NOT_FOUND HTTP status code (404) serverResponse.setStatusCode(HttpStatusCode.NOT_FOUND_404); String message = environment.getProperty("http.errors[404].message", ""); serverResponse.headers().set(HttpHeaders.CONTENT_LENGTH, Integer.toString(message.length())); serverResponse.headers().set(HttpHeaders.CONTENT_TYPE, "text/plain"); serverResponse.headers().set(HttpHeaders.CONNECTION, HttpHeadersValues.CONNECTION_CLOSE); serverResponse.write(Buffer.buffer(message)); serverResponse.end(); }
@Override public void handle(RoutingContext context) { final String userId = context.request().getParam("id"); userService.delete(userId) .subscribe( () -> context.response().setStatusCode(204).end(), error -> context.fail(error)); }
@Override public void handle(RoutingContext context) { final String groupId = context.request().getParam("id"); groupService.delete(groupId) .subscribe( () -> context.response().setStatusCode(204).end(), error -> context.fail(error)); }