Search in sources :

Example 1 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class StandaloneMockMvcBuilder method registerMvcSingletons.

private void registerMvcSingletons(StubWebApplicationContext wac) {
    StandaloneConfiguration config = new StandaloneConfiguration();
    config.setApplicationContext(wac);
    wac.addBeans(this.controllerAdvice);
    StaticRequestMappingHandlerMapping hm = config.getHandlerMapping();
    hm.setServletContext(wac.getServletContext());
    hm.setApplicationContext(wac);
    hm.afterPropertiesSet();
    hm.registerHandlers(this.controllers);
    wac.addBean("requestMappingHandlerMapping", hm);
    RequestMappingHandlerAdapter handlerAdapter = config.requestMappingHandlerAdapter();
    handlerAdapter.setServletContext(wac.getServletContext());
    handlerAdapter.setApplicationContext(wac);
    handlerAdapter.afterPropertiesSet();
    wac.addBean("requestMappingHandlerAdapter", handlerAdapter);
    wac.addBean("handlerExceptionResolver", config.handlerExceptionResolver());
    wac.addBeans(initViewResolvers(wac));
    wac.addBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, this.localeResolver);
    wac.addBean(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, new FixedThemeResolver());
    wac.addBean(DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, new DefaultRequestToViewNameTranslator());
    this.flashMapManager = new SessionFlashMapManager();
    wac.addBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, this.flashMapManager);
}
Also used : FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) DefaultRequestToViewNameTranslator(org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)

Example 2 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-boot by spring-projects.

the class HypermediaAutoConfigurationTests method customizationOfSupportedMediaTypesCanBeDisabled.

@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(BaseConfig.class);
    EnvironmentTestUtils.addEnvironment(this.context, "spring.hateoas.use-hal-as-default-json-media-type:false");
    this.context.refresh();
    RequestMappingHandlerAdapter handlerAdapter = this.context.getBean(RequestMappingHandlerAdapter.class);
    for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
        if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
            assertThat(converter.getSupportedMediaTypes()).containsExactly(MediaTypes.HAL_JSON);
        }
    }
}
Also used : TypeConstrainedMappingJackson2HttpMessageConverter(org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 3 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method overrideIgnoreDefaultModelOnRedirect.

@Test
public void overrideIgnoreDefaultModelOnRedirect() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "spring.mvc.ignore-default-model-on-redirect:false");
    this.context.register(Config.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    RequestMappingHandlerAdapter adapter = this.context.getBean(RequestMappingHandlerAdapter.class);
    assertThat(adapter).extracting("ignoreDefaultModelOnRedirect").containsExactly(false);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.Test)

Example 4 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method ignoreDefaultModelOnRedirectIsTrue.

@Test
public void ignoreDefaultModelOnRedirectIsTrue() throws Exception {
    load();
    RequestMappingHandlerAdapter adapter = this.context.getBean(RequestMappingHandlerAdapter.class);
    assertThat(adapter).extracting("ignoreDefaultModelOnRedirect").containsExactly(true);
}
Also used : RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.Test)

Example 5 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method customAsyncRequestTimeout.

@Test
public void customAsyncRequestTimeout() throws Exception {
    load("spring.mvc.async.request-timeout:123456");
    RequestMappingHandlerAdapter adapter = this.context.getBean(RequestMappingHandlerAdapter.class);
    Object actual = ReflectionTestUtils.getField(adapter, "asyncRequestTimeout");
    assertThat(actual).isEqualTo(123456L);
}
Also used : RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.Test)

Aggregations

RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)21 Test (org.junit.Test)17 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)5 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)4 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)4 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ConversionService (org.springframework.core.convert.ConversionService)3 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)3 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)3 ConversionServiceExposingInterceptor (org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor)3 List (java.util.List)2 ApplicationContext (org.springframework.context.ApplicationContext)2 Bean (org.springframework.context.annotation.Bean)2 FormattingConversionService (org.springframework.format.support.FormattingConversionService)2 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)2 HandlerExceptionResolverComposite (org.springframework.web.servlet.handler.HandlerExceptionResolverComposite)2