use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method defaultAsyncRequestTimeout.
@Test
public void defaultAsyncRequestTimeout() throws Exception {
load();
RequestMappingHandlerAdapter adapter = this.context.getBean(RequestMappingHandlerAdapter.class);
assertThat(ReflectionTestUtils.getField(adapter, "asyncRequestTimeout")).isNull();
}
use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method requestMappingHandlerAdapter.
/**
* Returns a {@link RequestMappingHandlerAdapter} for processing requests
* through annotated controller methods. Consider overriding one of these
* other more fine-grained methods:
* <ul>
* <li>{@link #addArgumentResolvers} for adding custom argument resolvers.
* <li>{@link #addReturnValueHandlers} for adding custom return value handlers.
* <li>{@link #configureMessageConverters} for adding custom message converters.
* </ul>
*/
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
RequestMappingHandlerAdapter adapter = createRequestMappingHandlerAdapter();
adapter.setContentNegotiationManager(mvcContentNegotiationManager());
adapter.setMessageConverters(getMessageConverters());
adapter.setWebBindingInitializer(getConfigurableWebBindingInitializer());
adapter.setCustomArgumentResolvers(getArgumentResolvers());
adapter.setCustomReturnValueHandlers(getReturnValueHandlers());
if (jackson2Present) {
adapter.setRequestBodyAdvice(Collections.singletonList(new JsonViewRequestBodyAdvice()));
adapter.setResponseBodyAdvice(Collections.singletonList(new JsonViewResponseBodyAdvice()));
}
AsyncSupportConfigurer configurer = new AsyncSupportConfigurer();
configureAsyncSupport(configurer);
if (configurer.getTaskExecutor() != null) {
adapter.setTaskExecutor(configurer.getTaskExecutor());
}
if (configurer.getTimeout() != null) {
adapter.setAsyncRequestTimeout(configurer.getTimeout());
}
adapter.setCallableInterceptors(configurer.getCallableInterceptors());
adapter.setDeferredResultInterceptors(configurer.getDeferredResultInterceptors());
return adapter;
}
use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method requestMappingHandlerAdapter.
@Test
public void requestMappingHandlerAdapter() throws Exception {
ApplicationContext context = initContext(WebConfig.class);
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
assertEquals(11, converters.size());
converters.stream().filter(converter -> converter instanceof AbstractJackson2HttpMessageConverter).forEach(converter -> {
ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper();
assertFalse(mapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
assertFalse(mapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
assertFalse(mapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES));
if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
assertEquals(XmlMapper.class, mapper.getClass());
}
});
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
assertNotNull(initializer);
ConversionService conversionService = initializer.getConversionService();
assertNotNull(conversionService);
assertTrue(conversionService instanceof FormattingConversionService);
Validator validator = initializer.getValidator();
assertNotNull(validator);
assertTrue(validator instanceof LocalValidatorFactoryBean);
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
@SuppressWarnings("unchecked") List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
assertEquals(2, bodyAdvice.size());
assertEquals(JsonViewRequestBodyAdvice.class, bodyAdvice.get(0).getClass());
assertEquals(JsonViewResponseBodyAdvice.class, bodyAdvice.get(1).getClass());
}
use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.
the class MvcNamespaceTests method testCustomConversionService.
@Test(expected = TypeMismatchException.class)
public void testCustomConversionService() throws Exception {
loadBeanDefinitions("mvc-config-custom-conversion-service.xml", 14);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
// default web binding initializer behavior test
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setRequestURI("/accounts/12345");
request.addParameter("date", "2009-10-31");
MockHttpServletResponse response = new MockHttpServletResponse();
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(1, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
interceptor.preHandle(request, response, handler);
assertSame(appContext.getBean("conversionService"), request.getAttribute(ConversionService.class.getName()));
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
adapter.handle(request, response, handlerMethod);
}
use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.
the class DelegatingWebMvcConfigurationTests method configureMessageConverters.
@Test
public void configureMessageConverters() {
final HttpMessageConverter customConverter = mock(HttpMessageConverter.class);
final StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
List<WebMvcConfigurer> configurers = new ArrayList<>();
configurers.add(new WebMvcConfigurerAdapter() {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(stringConverter);
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(0, customConverter);
}
});
delegatingConfig = new DelegatingWebMvcConfiguration();
delegatingConfig.setConfigurers(configurers);
RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();
assertEquals("Only one custom converter should be registered", 2, adapter.getMessageConverters().size());
assertSame(customConverter, adapter.getMessageConverters().get(0));
assertSame(stringConverter, adapter.getMessageConverters().get(1));
}
Aggregations