use of org.springframework.web.servlet.function.RouterFunction in project spring-framework by spring-projects.
the class RouterFunctionMapping method initRouterFunction.
/**
* Detect a all {@linkplain RouterFunction router functions} in the
* current application context.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void initRouterFunction() {
ApplicationContext applicationContext = obtainApplicationContext();
Map<String, RouterFunction> beans = (this.detectHandlerFunctionsInAncestorContexts ? BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RouterFunction.class) : applicationContext.getBeansOfType(RouterFunction.class));
List<RouterFunction> routerFunctions = new ArrayList<>(beans.values());
this.routerFunction = routerFunctions.stream().reduce(RouterFunction::andOther).orElse(null);
logRouterFunctions(routerFunctions);
}
use of org.springframework.web.servlet.function.RouterFunction in project spring-framework by spring-projects.
the class RouterFunctionMappingTests method normal.
@Test
void normal() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = request -> Optional.of(handlerFunction);
RouterFunctionMapping mapping = new RouterFunctionMapping(routerFunction);
mapping.setMessageConverters(this.messageConverters);
MockHttpServletRequest request = createTestRequest("/match");
HandlerExecutionChain result = mapping.getHandler(request);
assertThat(result).isNotNull();
assertThat(result.getHandler()).isSameAs(handlerFunction);
}
use of org.springframework.web.servlet.function.RouterFunction in project spring-framework by spring-projects.
the class RouterFunctionMappingTests method noMatch.
@Test
void noMatch() throws Exception {
RouterFunction<ServerResponse> routerFunction = request -> Optional.empty();
RouterFunctionMapping mapping = new RouterFunctionMapping(routerFunction);
mapping.setMessageConverters(this.messageConverters);
MockHttpServletRequest request = createTestRequest("/match");
HandlerExecutionChain result = mapping.getHandler(request);
assertThat(result).isNull();
}
use of org.springframework.web.servlet.function.RouterFunction in project springdoc-openapi by springdoc.
the class RouterFunctionWebMvcProvider method getRouterFunctionPaths.
/**
* Gets web mvc router function paths.
*
* @return the web mvc router function paths
*/
public Optional<Map<String, AbstractRouterFunctionVisitor>> getRouterFunctionPaths() {
Map<String, RouterFunction> routerBeans = applicationContext.getBeansOfType(RouterFunction.class);
if (CollectionUtils.isEmpty(routerBeans))
return Optional.empty();
Map<String, AbstractRouterFunctionVisitor> routerFunctionVisitorMap = new HashMap<>();
for (Map.Entry<String, RouterFunction> entry : routerBeans.entrySet()) {
RouterFunction routerFunction = entry.getValue();
RouterFunctionVisitor routerFunctionVisitor = new RouterFunctionVisitor();
routerFunction.accept(routerFunctionVisitor);
routerFunctionVisitorMap.put(entry.getKey(), routerFunctionVisitor);
}
return Optional.of(routerFunctionVisitorMap);
}
use of org.springframework.web.servlet.function.RouterFunction 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.setMessageConverters(this.messageConverters);
PathPatternParser patternParser = new PathPatternParser();
patternParser.setCaseSensitive(false);
mapping.setPatternParser(patternParser);
mapping.afterPropertiesSet();
MockHttpServletRequest request = createTestRequest("/FOO");
HandlerExecutionChain result = mapping.getHandler(request);
assertThat(result).isNotNull();
assertThat(result.getHandler()).isSameAs(handlerFunction);
}
Aggregations