use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method resourceHandlerMapping.
/**
* Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped
* resource handlers. To configure resource handling, override
* {@link #addResourceHandlers}.
*/
@Bean
public HandlerMapping resourceHandlerMapping() {
ResourceHandlerRegistry registry = new ResourceHandlerRegistry(this.applicationContext, this.servletContext, mvcContentNegotiationManager());
addResourceHandlers(registry);
AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
if (handlerMapping != null) {
handlerMapping.setPathMatcher(mvcPathMatcher());
handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
handlerMapping.setInterceptors(new ResourceUrlProviderExposingInterceptor(mvcResourceUrlProvider()));
handlerMapping.setCorsConfigurations(getCorsConfigurations());
} else {
handlerMapping = new EmptyHandlerMapping();
}
return handlerMapping;
}
use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method defaultServletHandlerMapping.
/**
* Return a handler mapping ordered at Integer.MAX_VALUE with a mapped
* default servlet handler. To configure "default" Servlet handling,
* override {@link #configureDefaultServletHandling}.
*/
@Bean
public HandlerMapping defaultServletHandlerMapping() {
DefaultServletHandlerConfigurer configurer = new DefaultServletHandlerConfigurer(servletContext);
configureDefaultServletHandling(configurer);
AbstractHandlerMapping handlerMapping = configurer.getHandlerMapping();
handlerMapping = handlerMapping != null ? handlerMapping : new EmptyHandlerMapping();
return handlerMapping;
}
use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method emptyViewControllerHandlerMapping.
@Test
public void emptyViewControllerHandlerMapping() {
ApplicationContext context = initContext(WebConfig.class);
String name = "viewControllerHandlerMapping";
AbstractHandlerMapping handlerMapping = context.getBean(name, AbstractHandlerMapping.class);
assertNotNull(handlerMapping);
assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());
assertTrue(handlerMapping.getClass().getName().endsWith("EmptyHandlerMapping"));
}
use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method emptyDefaultServletHandlerMapping.
@Test
public void emptyDefaultServletHandlerMapping() {
ApplicationContext context = initContext(WebConfig.class);
String name = "defaultServletHandlerMapping";
AbstractHandlerMapping handlerMapping = context.getBean(name, AbstractHandlerMapping.class);
assertNotNull(handlerMapping);
assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());
assertTrue(handlerMapping.getClass().getName().endsWith("EmptyHandlerMapping"));
}
use of org.springframework.web.servlet.handler.AbstractHandlerMapping in project spring-framework by spring-projects.
the class MvcNamespaceTests method testCors.
@Test
public void testCors() {
loadBeanDefinitions("mvc-config-cors.xml");
String[] beanNames = appContext.getBeanNamesForType(AbstractHandlerMapping.class);
assertThat(beanNames.length).isEqualTo(2);
for (String beanName : beanNames) {
AbstractHandlerMapping handlerMapping = (AbstractHandlerMapping) appContext.getBean(beanName);
assertThat(handlerMapping).isNotNull();
DirectFieldAccessor accessor = new DirectFieldAccessor(handlerMapping);
Map<String, CorsConfiguration> configs = ((UrlBasedCorsConfigurationSource) accessor.getPropertyValue("corsConfigurationSource")).getCorsConfigurations();
assertThat(configs).isNotNull();
assertThat(configs.size()).isEqualTo(2);
CorsConfiguration config = configs.get("/api/**");
assertThat(config).isNotNull();
assertThat(config.getAllowedOrigins().toArray()).isEqualTo(new String[] { "https://domain1.com", "https://domain2.com" });
assertThat(config.getAllowedOriginPatterns().toArray()).isEqualTo(new String[] { "http://*.domain.com" });
assertThat(config.getAllowedMethods().toArray()).isEqualTo(new String[] { "GET", "PUT" });
assertThat(config.getAllowedHeaders().toArray()).isEqualTo(new String[] { "header1", "header2", "header3" });
assertThat(config.getExposedHeaders().toArray()).isEqualTo(new String[] { "header1", "header2" });
assertThat(config.getAllowCredentials()).isFalse();
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(123));
config = configs.get("/resources/**");
assertThat(config.getAllowedOrigins().toArray()).isEqualTo(new String[] { "https://domain1.com" });
assertThat(config.getAllowedMethods().toArray()).isEqualTo(new String[] { "GET", "HEAD", "POST" });
assertThat(config.getAllowedHeaders().toArray()).isEqualTo(new String[] { "*" });
assertThat(config.getExposedHeaders()).isNull();
assertThat(config.getAllowCredentials()).isNull();
assertThat(config.getMaxAge()).isEqualTo(1800L);
}
}
Aggregations