use of org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class WebFluxConfigurationSupport method requestMappingHandlerAdapter.
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
RequestMappingHandlerAdapter adapter = createRequestMappingHandlerAdapter();
adapter.setMessageReaders(getMessageReaders());
adapter.setWebBindingInitializer(getConfigurableWebBindingInitializer());
adapter.setReactiveAdapterRegistry(webFluxAdapterRegistry());
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
addArgumentResolvers(resolvers);
if (!resolvers.isEmpty()) {
adapter.setCustomArgumentResolvers(resolvers);
}
return adapter;
}
use of org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class ControllerMethodResolver method initResolvers.
private static List<HandlerMethodArgumentResolver> initResolvers(ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry, ConfigurableApplicationContext context, boolean supportDataBinding, List<HttpMessageReader<?>> readers) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
boolean requestMappingMethod = !readers.isEmpty() && supportDataBinding;
// Annotation-based...
List<HandlerMethodArgumentResolver> result = new ArrayList<>(30);
result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, false));
result.add(new RequestParamMapMethodArgumentResolver(adapterRegistry));
result.add(new PathVariableMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new PathVariableMapMethodArgumentResolver(adapterRegistry));
result.add(new MatrixVariableMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new MatrixVariableMapMethodArgumentResolver(adapterRegistry));
if (!readers.isEmpty()) {
result.add(new RequestBodyMethodArgumentResolver(readers, adapterRegistry));
result.add(new RequestPartMethodArgumentResolver(readers, adapterRegistry));
}
if (supportDataBinding) {
result.add(new ModelAttributeMethodArgumentResolver(adapterRegistry, false));
}
result.add(new RequestHeaderMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new RequestHeaderMapMethodArgumentResolver(adapterRegistry));
result.add(new CookieValueMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new ExpressionValueMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new SessionAttributeMethodArgumentResolver(beanFactory, adapterRegistry));
result.add(new RequestAttributeMethodArgumentResolver(beanFactory, adapterRegistry));
// Type-based...
if (!readers.isEmpty()) {
result.add(new HttpEntityMethodArgumentResolver(readers, adapterRegistry));
}
result.add(new ModelMethodArgumentResolver(adapterRegistry));
if (supportDataBinding) {
result.add(new ErrorsMethodArgumentResolver(adapterRegistry));
}
result.add(new ServerWebExchangeMethodArgumentResolver(adapterRegistry));
result.add(new PrincipalMethodArgumentResolver(adapterRegistry));
if (requestMappingMethod) {
result.add(new SessionStatusMethodArgumentResolver());
}
result.add(new WebSessionMethodArgumentResolver(adapterRegistry));
if (KotlinDetector.isKotlinPresent()) {
result.add(new ContinuationHandlerMethodArgumentResolver());
}
// Custom...
result.addAll(customResolvers.getCustomResolvers());
// Catch-all...
result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, true));
if (supportDataBinding) {
result.add(new ModelAttributeMethodArgumentResolver(adapterRegistry, true));
}
return result;
}
use of org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class ControllerMethodResolverTests method modelAttributeArgumentResolvers.
@Test
public void modelAttributeArgumentResolvers() {
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod);
assertThat(methods.size()).as("Expected one each from Controller + ControllerAdvice").isEqualTo(2);
InvocableHandlerMethod invocable = methods.get(0);
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
AtomicInteger index = new AtomicInteger(-1);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CookieValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ExpressionValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(SessionAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ErrorsMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ServerWebExchangeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PrincipalMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(WebSessionMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ContinuationHandlerMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomSyncArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
}
use of org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class ControllerMethodResolverTests method requestMappingArgumentResolvers.
@Test
public void requestMappingArgumentResolvers() {
InvocableHandlerMethod invocable = this.methodResolver.getRequestMappingMethod(this.handlerMethod);
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
AtomicInteger index = new AtomicInteger(-1);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestBodyMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestPartMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CookieValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ExpressionValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(SessionAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(HttpEntityMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ErrorsMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ServerWebExchangeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PrincipalMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(SessionStatusMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(WebSessionMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ContinuationHandlerMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomSyncArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
}
use of org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver in project spring-boot by spring-projects.
the class WebFluxAutoConfigurationTests method shouldRegisterCustomHandlerMethodArgumentResolver.
@SuppressWarnings("unchecked")
@Test
void shouldRegisterCustomHandlerMethodArgumentResolver() {
this.contextRunner.withUserConfiguration(CustomArgumentResolvers.class).run((context) -> {
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
List<HandlerMethodArgumentResolver> customResolvers = (List<HandlerMethodArgumentResolver>) ReflectionTestUtils.getField(adapter.getArgumentResolverConfigurer(), "customResolvers");
assertThat(customResolvers).contains(context.getBean("firstResolver", HandlerMethodArgumentResolver.class), context.getBean("secondResolver", HandlerMethodArgumentResolver.class));
});
}
Aggregations