Search in sources :

Example 1 with HttpServerRoutes

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();
}
Also used : HttpServerRoutes(reactor.netty.http.server.HttpServerRoutes) EventExecutor(io.netty.util.concurrent.EventExecutor) AfterClass(org.junit.AfterClass) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) HttpServer(reactor.netty.http.server.HttpServer) Ignore(org.junit.Ignore) After(org.junit.After) Schedulers(reactor.core.scheduler.Schedulers) DisposableServer(reactor.netty.DisposableServer) HttpServerRoutes(reactor.netty.http.server.HttpServerRoutes) SERVER(brave.Span.Kind.SERVER) ITHttpServer(brave.test.http.ITHttpServer) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup)

Aggregations

SERVER (brave.Span.Kind.SERVER)1 ITHttpServer (brave.test.http.ITHttpServer)1 ChannelGroup (io.netty.channel.group.ChannelGroup)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 DefaultEventExecutor (io.netty.util.concurrent.DefaultEventExecutor)1 EventExecutor (io.netty.util.concurrent.EventExecutor)1 IOException (java.io.IOException)1 TimeUnit (java.util.concurrent.TimeUnit)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 After (org.junit.After)1 AfterClass (org.junit.AfterClass)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Mono (reactor.core.publisher.Mono)1 Schedulers (reactor.core.scheduler.Schedulers)1 DisposableServer (reactor.netty.DisposableServer)1 HttpServer (reactor.netty.http.server.HttpServer)1 HttpServerRoutes (reactor.netty.http.server.HttpServerRoutes)1