Search in sources :

Example 11 with AbstractHandlerMapping

use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.

the class WebMvcConfigurationSupportTests method emptyResourceHandlerMapping.

@Test
public void emptyResourceHandlerMapping() {
    ApplicationContext context = initContext(WebConfig.class);
    AbstractHandlerMapping handlerMapping = context.getBean("resourceHandlerMapping", AbstractHandlerMapping.class);
    assertNotNull(handlerMapping);
    assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());
    assertTrue(handlerMapping.getClass().getName().endsWith("EmptyHandlerMapping"));
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Test(org.junit.Test)

Example 12 with AbstractHandlerMapping

use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.

the class WebMvcConfigurationSupport method viewControllerHandlerMapping.

/**
 * Return a handler mapping ordered at 1 to map URL paths directly to
 * view names. To configure view controllers, override
 * {@link #addViewControllers}.
 */
@Bean
@Nullable
public HandlerMapping viewControllerHandlerMapping(@Qualifier("mvcConversionService") FormattingConversionService conversionService, @Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) {
    ViewControllerRegistry registry = new ViewControllerRegistry(this.applicationContext);
    addViewControllers(registry);
    AbstractHandlerMapping handlerMapping = registry.buildHandlerMapping();
    if (handlerMapping == null) {
        return null;
    }
    PathMatchConfigurer pathConfig = getPathMatchConfigurer();
    if (pathConfig.getPatternParser() != null) {
        handlerMapping.setPatternParser(pathConfig.getPatternParser());
    } else {
        handlerMapping.setUrlPathHelper(pathConfig.getUrlPathHelperOrDefault());
        handlerMapping.setPathMatcher(pathConfig.getPathMatcherOrDefault());
    }
    handlerMapping.setInterceptors(getInterceptors(conversionService, resourceUrlProvider));
    handlerMapping.setCorsConfigurations(getCorsConfigurations());
    return handlerMapping;
}
Also used : AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Nullable(org.springframework.lang.Nullable) Bean(org.springframework.context.annotation.Bean)

Example 13 with AbstractHandlerMapping

use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.

the class DelegatingWebMvcConfigurationIntegrationTests method viewControllerHandlerMappingWithPrimaryUsesQualifiedPathMatcher.

@Test
void viewControllerHandlerMappingWithPrimaryUsesQualifiedPathMatcher() {
    load(registerPrimaryBean("testPathMatcher", PathMatcher.class).andThen(context -> context.registerBean(ViewControllerConfiguration.class)));
    AbstractHandlerMapping handlerMapping = this.context.getBean("viewControllerHandlerMapping", AbstractHandlerMapping.class);
    assertThat(handlerMapping.getPathMatcher()).isSameAs(this.context.getBean("mvcPathMatcher"));
    assertThat(this.context.getBeansOfType(PathMatcher.class)).containsOnlyKeys("mvcPathMatcher", "testPathMatcher");
}
Also used : Validator(org.springframework.validation.Validator) PathMatcher(org.springframework.util.PathMatcher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AnnotationConfigUtils(org.springframework.context.annotation.AnnotationConfigUtils) AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) AfterEach(org.junit.jupiter.api.AfterEach) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) UrlPathHelper(org.springframework.web.util.UrlPathHelper) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ConversionService(org.springframework.core.convert.ConversionService) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Mockito.mock(org.mockito.Mockito.mock) AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Test(org.junit.jupiter.api.Test)

Example 14 with AbstractHandlerMapping

use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.

the class DelegatingWebMvcConfigurationIntegrationTests method resourceHandlerMappingWithPrimaryUsesQualifiedUrlPathHelper.

@Test
void resourceHandlerMappingWithPrimaryUsesQualifiedUrlPathHelper() {
    load(registerPrimaryBean("testUrlPathHelper", UrlPathHelper.class).andThen(context -> context.registerBean(ResourceHandlerConfiguration.class)));
    AbstractHandlerMapping handlerMapping = this.context.getBean("resourceHandlerMapping", AbstractHandlerMapping.class);
    assertThat(handlerMapping.getUrlPathHelper()).isSameAs(this.context.getBean("mvcUrlPathHelper"));
    assertThat(this.context.getBeansOfType(UrlPathHelper.class)).containsOnlyKeys("mvcUrlPathHelper", "testUrlPathHelper");
}
Also used : Validator(org.springframework.validation.Validator) PathMatcher(org.springframework.util.PathMatcher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AnnotationConfigUtils(org.springframework.context.annotation.AnnotationConfigUtils) AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) AfterEach(org.junit.jupiter.api.AfterEach) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) UrlPathHelper(org.springframework.web.util.UrlPathHelper) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ConversionService(org.springframework.core.convert.ConversionService) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Mockito.mock(org.mockito.Mockito.mock) AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Test(org.junit.jupiter.api.Test)

Example 15 with AbstractHandlerMapping

use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.

the class DelegatingWebMvcConfigurationIntegrationTests method viewControllerHandlerMappingWithPrimaryUsesQualifiedUrlPathHelper.

@Test
void viewControllerHandlerMappingWithPrimaryUsesQualifiedUrlPathHelper() {
    load(registerPrimaryBean("testUrlPathHelper", UrlPathHelper.class).andThen(context -> context.registerBean(ViewControllerConfiguration.class)));
    AbstractHandlerMapping handlerMapping = this.context.getBean("viewControllerHandlerMapping", AbstractHandlerMapping.class);
    assertThat(handlerMapping.getUrlPathHelper()).isSameAs(this.context.getBean("mvcUrlPathHelper"));
    assertThat(this.context.getBeansOfType(UrlPathHelper.class)).containsOnlyKeys("mvcUrlPathHelper", "testUrlPathHelper");
}
Also used : Validator(org.springframework.validation.Validator) PathMatcher(org.springframework.util.PathMatcher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AnnotationConfigUtils(org.springframework.context.annotation.AnnotationConfigUtils) AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) AfterEach(org.junit.jupiter.api.AfterEach) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) UrlPathHelper(org.springframework.web.util.UrlPathHelper) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ConversionService(org.springframework.core.convert.ConversionService) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) Mockito.mock(org.mockito.Mockito.mock) AbstractHandlerMapping(org.springframework.web.servlet.handler.AbstractHandlerMapping) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractHandlerMapping (org.springframework.web.servlet.handler.AbstractHandlerMapping)17 Test (org.junit.jupiter.api.Test)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Mockito.mock (org.mockito.Mockito.mock)5 Bean (org.springframework.context.annotation.Bean)5 Consumer (java.util.function.Consumer)4 AfterEach (org.junit.jupiter.api.AfterEach)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 AnnotationConfigUtils (org.springframework.context.annotation.AnnotationConfigUtils)4 Configuration (org.springframework.context.annotation.Configuration)4 ConversionService (org.springframework.core.convert.ConversionService)4 PathMatcher (org.springframework.util.PathMatcher)4 Validator (org.springframework.validation.Validator)4 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)4 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)4 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)4 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)4 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)4 UrlPathHelper (org.springframework.web.util.UrlPathHelper)4 Test (org.junit.Test)3