BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> getHandler() { return (req, resp) -> { req.requestHeaders() .entries() .forEach(entry1 -> System.out.println(String.format("header [%s=>%s]", entry1.getKey(), entry1.getValue()))); req.params() .entrySet() .forEach(entry2 -> System.out.println(String.format("params [%s=>%s]", entry2.getKey(), entry2.getValue()))); StringBuilder response = new StringBuilder().append("hello ") .append(req.params() .get("name")); System.out.println(String.format("%s from thread %s", response.toString(), Thread.currentThread())); return resp.sendString(Flux.just(response.toString())); }; }
@Override public Publisher<Void> apply(HttpServerRequest httpRequest, HttpServerResponse httpResponse) { LOGGER.debug( "Accepted request: {}, headers: {}, params: {}", httpRequest, httpRequest.requestHeaders(), httpRequest.params()); if (httpRequest.method() != POST) { LOGGER.error("Unsupported HTTP method. Expected POST, actual {}", httpRequest.method()); return methodNotAllowed(httpResponse); } return httpRequest .receive() .aggregate() .map(ByteBuf::retain) .doOnNext(content -> metrics.markRequest()) .flatMap(content -> handleRequest(content, httpRequest, httpResponse)) .doOnSuccess(avoid -> metrics.markResponse()) .onErrorResume(t -> error(httpResponse, ExceptionProcessor.toMessage(t))); }
@Override public Publisher<Void> apply(HttpServerRequest httpRequest, HttpServerResponse httpResponse) { LOGGER.debug( "Accepted request: {}, headers: {}, params: {}", httpRequest, httpRequest.requestHeaders(), httpRequest.params()); if (httpRequest.method() != POST) { LOGGER.error("Unsupported HTTP method. Expected POST, actual {}", httpRequest.method()); return methodNotAllowed(httpResponse); } return httpRequest .receive() .aggregate() .map(ByteBuf::retain) .doOnNext(content -> metrics.markRequest()) .flatMap(content -> handleRequest(content, httpRequest, httpResponse)) .doOnSuccess(avoid -> metrics.markResponse()) .onErrorResume(t -> error(httpResponse, DefaultErrorMapper.INSTANCE.toMessage(t))); }