@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 { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { HttpServerResponse resp = req.response(); String contentType = req.getHeader("Content-Type"); if (contentType != null) { resp.putHeader("Content-Type", contentType); } resp.setChunked(true); req.toFlowable().subscribe( resp::write, err -> {}, resp::end ); }); server.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()); }
@Override public void handle(RoutingContext context) { serviceProviderConfigService.get() .subscribe( config -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .end(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(config)), error -> context.fail(error)); }
@Override public void handle(RoutingContext context) { serviceProviderConfigService.get() .subscribe( config -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .end(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(config)), error -> context.fail(error)); }
private void writeHeaders(HttpServerResponse response, MultiMap headers) { headers.names().stream() .filter(this::headerFilter) .forEach( name -> headers .getAll(name) .forEach(value -> response.putHeader(name, value)) ); }
private void writeHeaders(HttpServerResponse response, MultiMap headers) { headers.names().stream() .filter(this::headerFilter) .forEach( name -> headers .getAll(name) .forEach(value -> response.putHeader(name, value)) ); }
@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()); }
/** * 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 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 cause error message */ protected void internalError(RoutingContext context, String cause) { context.response().setStatusCode(500) .putHeader("content-type", "application/json") .end(new JsonObject().put("error", cause).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); }