use of org.springframework.web.reactive.function.server.HandlerFunction 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.HandlerFunction 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.HandlerFunction in project spring-framework by spring-projects.
the class HandlerFunctionAdapter method handle.
@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
HandlerFunction<?> handlerFunction = (HandlerFunction<?>) handler;
ServerRequest request = exchange.getRequiredAttribute(RouterFunctions.REQUEST_ATTRIBUTE);
return handlerFunction.handle(request).map(response -> new HandlerResult(handlerFunction, response, HANDLER_FUNCTION_RETURN_TYPE));
}
Aggregations