Refine search
@Override public void handle(Void aVoid) { if (!finished.compareAndSet(false, true)) return; VertxHttpServerAdapter.setCurrentMethodAndPath( context.request().rawMethod(), context.currentRoute().getPath() ); try { serverHandler.handleSend(context.response(), context.failure(), span); } finally { VertxHttpServerAdapter.setCurrentMethodAndPath(null, null); } } }
private void sendDirectoryListing(String dir, RoutingContext context) { FileSystem fileSystem = context.vertx().fileSystem(); HttpServerRequest request = context.request(); request.response().end( directoryTemplate(context.vertx()).replace("{directory}", normalizedDir) .replace("{parent}", parent) request.response().end(json.encode()); } else { String file; request.response().end(buffer.toString());
private void now(RoutingContext context) { logger.info("Time request from {}", context.request().remoteAddress()); JsonObject data = new JsonObject() .put("powered-by", "vertx") .put("current-time", System.currentTimeMillis()); context.response() .putHeader("Content-Type", "application/json") .end(data.encode()); } }
static void setJSESSIONID(SockJSHandlerOptions options, RoutingContext rc) { String cookies = rc.request().getHeader("cookie"); if (options.isInsertJSESSIONID()) { //Preserve existing JSESSIONID, if any if (cookies != null) { String[] parts; if (cookies.contains(";")) { parts = cookies.split(";"); } else { parts = new String[] {cookies}; } for (String part: parts) { if (part.startsWith("JSESSIONID")) { cookies = part + "; path=/"; break; } } } if (cookies == null) { cookies = "JSESSIONID=dummy; path=/"; } rc.response().putHeader("Set-Cookie", cookies); } }
private void handleAddProduct(RoutingContext routingContext) { String productID = routingContext.request().getParam("productID"); HttpServerResponse response = routingContext.response(); if (productID == null) { sendError(400, response); } else { JsonObject product = routingContext.getBodyAsJson(); if (product == null) { sendError(400, response); } else { products.put(productID, product); response.end(); } } }
public void sendFrame(String body) { if (log.isTraceEnabled()) log.trace("XHR sending frame"); if (!headersWritten) { HttpServerResponse resp = rc.response(); resp.putHeader("Content-Type", "application/javascript; charset=UTF-8"); setJSESSIONID(options, rc); setCORS(rc); if (rc.request().version() != HttpVersion.HTTP_1_0) { resp.setChunked(true); } // NOTE that this is streaming!!! // Client are not expecting to see Content-Length as we don't know it's value headersWritten = true; } }
private void handleAddProduct(RoutingContext routingContext) { String productID = routingContext.request().getParam("productID"); HttpServerResponse response = routingContext.response(); if (productID == null) { sendError(400, response); } else { JsonObject product = routingContext.getBodyAsJson(); if (product == null) { sendError(400, response); } else { products.put(productID, product); response.end(); } } }
@Override public void handle(RoutingContext context) { String cookieHeader = context.request().headers().get(COOKIE); if (cookieHeader != null) { Set<io.netty.handler.codec.http.cookie.Cookie> nettyCookies = ServerCookieDecoder.STRICT.decode(cookieHeader); for (io.netty.handler.codec.http.cookie.Cookie cookie : nettyCookies) { Cookie ourCookie = new CookieImpl(cookie); context.addCookie(ourCookie); } } context.addHeadersEndHandler(v -> { // save the cookies Set<Cookie> cookies = context.cookies(); for (Cookie cookie: cookies) { if (cookie.isChanged()) { context.response().headers().add(SET_COOKIE, cookie.encode()); } } }); context.next(); }
private void handleGetProduct(RoutingContext routingContext) { String productID = routingContext.request().getParam("productID"); HttpServerResponse response = routingContext.response(); if (productID == null) { sendError(400, response); } else { JsonObject product = products.get(productID); if (product == null) { sendError(404, response); } else { response.putHeader("content-type", "application/json").end(product.encodePrettily()); } } }
private void handleGetProduct(RoutingContext routingContext) { String productID = routingContext.request().getParam("productID"); HttpServerResponse response = routingContext.response(); if (productID == null) { sendError(400, response); } else { JsonObject product = products.get(productID); if (product == null) { sendError(404, response); } else { response.putHeader("content-type", "application/json").end(product.encode()); } } }
@Override public void start() { Router router = Router.router(vertx); router.get("/").handler(rc -> { String param = rc.request().getParam("name"); if (param == null) { param = "world"; } vertx.eventBus().<String>send("request", param, reply -> { if (reply.failed()) { rc.response().setStatusCode(400).end(reply.cause().getMessage()); } else { String content = reply.result().body(); rc.response().end(content); } }); }); vertx.createHttpServer() .requestHandler(router) .listen(8080); } }
private void handleGetProduct(RoutingContext routingContext) { String productID = routingContext.request().getParam("productID"); HttpServerResponse response = routingContext.response(); if (productID == null) { sendError(400, response); } else { SQLConnection conn = routingContext.get("conn"); conn.queryWithParams("SELECT id, name, price, weight FROM products where id = ?", new JsonArray().add(Integer.parseInt(productID)), query -> { if (query.failed()) { sendError(500, response); } else { if (query.result().getNumRows() == 0) { sendError(404, response); } else { response.putHeader("content-type", "application/json").end(query.result().getRows().get(0).encode()); } } }); } }
ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, "text/html").end(res.result()); } else { ctx.fail(res.cause()); ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json"); ctx.response().end(json.encode()); }); }); .put("username", ctx.request().getFormAttribute("username")) .put("email", ctx.request().getFormAttribute("email")) .put("fullname", ctx.request().getFormAttribute("fullname")) .put("location", ctx.request().getFormAttribute("location")) .put("age", ctx.request().getFormAttribute("age")) .put("gender", ctx.request().getFormAttribute("gender")); ctx.response().setStatusCode(201); ctx.response().end(); }); }); mongo.removeOne("users", new JsonObject().put("_id", ctx.request().getParam("id")), lookup -> {
HttpServerResponse httpServerResponse = ctx.response(); httpServerResponse.setChunked(true); MultiMap headers = ctx.request().headers(); for (String key : headers.names()) { httpServerResponse.write(key + ": "); httpServerResponse.write("<br>"); httpServerResponse.putHeader("Content-Type", "application/text").end("Success"); }); HttpServerResponse httpServerResponse = ctx.response(); httpServerResponse.setChunked(true); MultiMap headers = ctx.request().headers(); for (String key : headers.names()) { httpServerResponse.write(key + ": "); httpServerResponse.write("<br>"); httpServerResponse.putHeader("Content-Type", "application/text").end("Success"); });
List<String> authorities = new ArrayList<>(); for (String authority : ctx.request().params().getAll("authority")) { authorities.add(authority); ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end(jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(60).setPermissions (authorities))); }); ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end("this secret is not defcon!"); }); ctx.response().setStatusCode(403).end(); return;