use of org.springframework.web.reactive.function.server.ServerResponse in project spring-framework by spring-projects.
the class RouterFunctionMappingTests method mappedRequestShouldHoldAttributes.
@Test
void mappedRequestShouldHoldAttributes() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route().GET("/match", handlerFunction).build();
RouterFunctionMapping mapping = new RouterFunctionMapping(routerFunction);
mapping.setMessageReaders(this.codecConfigurer.getReaders());
ServerWebExchange exchange = createExchange("https://example.com/match");
Mono<Object> result = mapping.getHandler(exchange);
StepVerifier.create(result).expectNext(handlerFunction).expectComplete().verify();
PathPattern matchingPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
assertThat(matchingPattern).isNotNull();
assertThat(matchingPattern.getPatternString()).isEqualTo("/match");
ServerRequest serverRequest = exchange.getAttribute(RouterFunctions.REQUEST_ATTRIBUTE);
assertThat(serverRequest).isNotNull();
HandlerFunction<?> handler = exchange.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
assertThat(handler).isEqualTo(handlerFunction);
}
use of org.springframework.web.reactive.function.server.ServerResponse in project spring-framework by spring-projects.
the class RouterFunctionMappingTests method changeParser.
@Test
void changeParser() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route().GET("/foo", handlerFunction).POST("/bar", handlerFunction).build();
RouterFunctionMapping mapping = new RouterFunctionMapping(routerFunction);
mapping.setMessageReaders(this.codecConfigurer.getReaders());
mapping.setUseCaseSensitiveMatch(false);
mapping.afterPropertiesSet();
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com/FOO"));
Mono<Object> result = mapping.getHandler(exchange);
StepVerifier.create(result).expectNext(handlerFunction).verifyComplete();
}
use of org.springframework.web.reactive.function.server.ServerResponse in project spring-framework by spring-projects.
the class ServerResponseResultHandler method handleResult.
@Override
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
ServerResponse response = (ServerResponse) result.getReturnValue();
Assert.state(response != null, "No ServerResponse");
return response.writeTo(exchange, new ServerResponse.Context() {
@Override
public List<HttpMessageWriter<?>> messageWriters() {
return messageWriters;
}
@Override
public List<ViewResolver> viewResolvers() {
return viewResolvers;
}
});
}
Aggregations