Search in sources :

Example 1 with Task

use of com.baeldung.web.reactive.Task in project tutorials by eugenp.

the class Spring5ReactiveServerClientIntegrationTest method setUp.

@BeforeAll
public static void setUp() throws Exception {
    HttpServer server = HttpServer.create("localhost", 8080);
    RouterFunction<?> route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok().body(request.bodyToFlux(Task.class).map(ll -> new Task("TaskName", 1)), Task.class)).and(RouterFunctions.route(GET("/task"), request -> ServerResponse.ok().body(Mono.just("server is alive"), String.class)));
    HttpHandler httpHandler = RouterFunctions.toHttpHandler(route);
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
    nettyContext = server.newHandler(adapter).block();
}
Also used : ReactorHttpHandlerAdapter(org.springframework.http.server.reactive.ReactorHttpHandlerAdapter) RouterFunctions(org.springframework.web.reactive.function.server.RouterFunctions) POST(org.springframework.web.reactive.function.server.RequestPredicates.POST) Mono(reactor.core.publisher.Mono) AfterAll(org.junit.jupiter.api.AfterAll) Flux(reactor.core.publisher.Flux) HttpHandler(org.springframework.http.server.reactive.HttpHandler) BeforeAll(org.junit.jupiter.api.BeforeAll) RouterFunction(org.springframework.web.reactive.function.server.RouterFunction) ServerResponse(org.springframework.web.reactive.function.server.ServerResponse) Duration(java.time.Duration) Task(com.baeldung.web.reactive.Task) NettyContext(reactor.ipc.netty.NettyContext) GET(org.springframework.web.reactive.function.server.RequestPredicates.GET) HttpServer(reactor.ipc.netty.http.server.HttpServer) HttpHandler(org.springframework.http.server.reactive.HttpHandler) Task(com.baeldung.web.reactive.Task) HttpServer(reactor.ipc.netty.http.server.HttpServer) ReactorHttpHandlerAdapter(org.springframework.http.server.reactive.ReactorHttpHandlerAdapter) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Task (com.baeldung.web.reactive.Task)1 Duration (java.time.Duration)1 AfterAll (org.junit.jupiter.api.AfterAll)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 HttpHandler (org.springframework.http.server.reactive.HttpHandler)1 ReactorHttpHandlerAdapter (org.springframework.http.server.reactive.ReactorHttpHandlerAdapter)1 GET (org.springframework.web.reactive.function.server.RequestPredicates.GET)1 POST (org.springframework.web.reactive.function.server.RequestPredicates.POST)1 RouterFunction (org.springframework.web.reactive.function.server.RouterFunction)1 RouterFunctions (org.springframework.web.reactive.function.server.RouterFunctions)1 ServerResponse (org.springframework.web.reactive.function.server.ServerResponse)1 Flux (reactor.core.publisher.Flux)1 Mono (reactor.core.publisher.Mono)1 NettyContext (reactor.ipc.netty.NettyContext)1 HttpServer (reactor.ipc.netty.http.server.HttpServer)1