use of reactor.netty.http.server.HttpServerRoutes in project reactor-netty by reactor.
the class ITTracingHttpServerDecoratorTest method init.
@Override
protected void init() {
HttpServerRoutes routes = HttpServerRoutes.newRoutes().options("/", (req, res) -> res.send()).get("/foo", (req, res) -> res.sendString(Mono.just("bar"))).get("/baggage", (req, res) -> res.sendString(Mono.just(req.requestHeaders().getAsString(BAGGAGE_FIELD_KEY)))).get("/exception", (req, res) -> Mono.error(NOT_READY_ISE)).get("/badrequest", (req, res) -> res.status(400).send()).get("/async", (req, res) -> res.sendString(Mono.just("body").publishOn(Schedulers.boundedElastic()))).get("/exceptionAsync", (req, res) -> Mono.error(NOT_READY_ISE).publishOn(Schedulers.boundedElastic()).then()).get("/items/{itemId}", (req, res) -> res.sendString(Mono.justOrEmpty(req.param("itemId")))).get("/async_items/{itemId}", (req, res) -> res.sendString(Mono.justOrEmpty(req.param("itemId")).publishOn(Schedulers.boundedElastic()))).get("/nested/items/{itemId}", (req, res) -> res.sendString(Mono.justOrEmpty(req.param("itemId")))).get("/child", (req, res) -> {
httpTracing.tracing().tracer().nextSpan().name("child").start().finish();
return res.send();
});
ReactorNettyHttpTracing reactorNettyHttpTracing = ReactorNettyHttpTracing.create(httpTracing, s -> {
if ("/foo/bark".equals(s)) {
return "not_found";
}
int ind = s.lastIndexOf('/');
if (s.length() > 1 && ind > -1) {
return s.substring(0, ind);
}
return s;
});
group = new DefaultChannelGroup(executor);
disposableServer = reactorNettyHttpTracing.decorateHttpServer(HttpServer.create().port(0).wiretap(true).forwarded(true).channelGroup(group).handle(routes)).bindNow();
}
Aggregations