Search in sources :

Example 6 with UrlPathHelper

use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.

the class WebMvcConfigurationSupport method requestMappingHandlerMapping.

/**
	 * Return a {@link RequestMappingHandlerMapping} ordered at 0 for mapping
	 * requests to annotated controllers.
	 */
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
    RequestMappingHandlerMapping handlerMapping = createRequestMappingHandlerMapping();
    handlerMapping.setOrder(0);
    handlerMapping.setInterceptors(getInterceptors());
    handlerMapping.setContentNegotiationManager(mvcContentNegotiationManager());
    handlerMapping.setCorsConfigurations(getCorsConfigurations());
    PathMatchConfigurer configurer = getPathMatchConfigurer();
    if (configurer.isUseSuffixPatternMatch() != null) {
        handlerMapping.setUseSuffixPatternMatch(configurer.isUseSuffixPatternMatch());
    }
    if (configurer.isUseRegisteredSuffixPatternMatch() != null) {
        handlerMapping.setUseRegisteredSuffixPatternMatch(configurer.isUseRegisteredSuffixPatternMatch());
    }
    if (configurer.isUseTrailingSlashMatch() != null) {
        handlerMapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch());
    }
    UrlPathHelper pathHelper = configurer.getUrlPathHelper();
    if (pathHelper != null) {
        handlerMapping.setUrlPathHelper(pathHelper);
    }
    PathMatcher pathMatcher = configurer.getPathMatcher();
    if (pathMatcher != null) {
        handlerMapping.setPathMatcher(pathMatcher);
    }
    return handlerMapping;
}
Also used : AntPathMatcher(org.springframework.util.AntPathMatcher) PathMatcher(org.springframework.util.PathMatcher) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Bean(org.springframework.context.annotation.Bean)

Example 7 with UrlPathHelper

use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.

the class WebMvcConfigurationSupport method mvcResourceUrlProvider.

/**
	 * A {@link ResourceUrlProvider} bean for use with the MVC dispatcher.
	 * @since 4.1
	 */
@Bean
public ResourceUrlProvider mvcResourceUrlProvider() {
    ResourceUrlProvider urlProvider = new ResourceUrlProvider();
    UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper();
    if (pathHelper != null) {
        urlProvider.setUrlPathHelper(pathHelper);
    }
    PathMatcher pathMatcher = getPathMatchConfigurer().getPathMatcher();
    if (pathMatcher != null) {
        urlProvider.setPathMatcher(pathMatcher);
    }
    return urlProvider;
}
Also used : AntPathMatcher(org.springframework.util.AntPathMatcher) PathMatcher(org.springframework.util.PathMatcher) UrlPathHelper(org.springframework.web.util.UrlPathHelper) ResourceUrlProvider(org.springframework.web.servlet.resource.ResourceUrlProvider) Bean(org.springframework.context.annotation.Bean)

Example 8 with UrlPathHelper

use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.

the class WebMvcConfigurationSupportTests method defaultPathMatchConfiguration.

@Test
public void defaultPathMatchConfiguration() throws Exception {
    ApplicationContext context = initContext(WebConfig.class);
    UrlPathHelper urlPathHelper = context.getBean(UrlPathHelper.class);
    PathMatcher pathMatcher = context.getBean(PathMatcher.class);
    assertNotNull(urlPathHelper);
    assertNotNull(pathMatcher);
    assertEquals(AntPathMatcher.class, pathMatcher.getClass());
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AntPathMatcher(org.springframework.util.AntPathMatcher) PathMatcher(org.springframework.util.PathMatcher) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Test(org.junit.Test)

Example 9 with UrlPathHelper

use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMappingTests method handleMatchUriTemplateVariables.

@SuppressWarnings("unchecked")
@Test
public void handleMatchUriTemplateVariables() {
    RequestMappingInfo key = RequestMappingInfo.paths("/{path1}/{path2}").build();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
    String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
    this.handlerMapping.handleMatch(key, lookupPath, request);
    String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
    Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);
    assertNotNull(uriVariables);
    assertEquals("1", uriVariables.get("path1"));
    assertEquals("2", uriVariables.get("path2"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test)

Example 10 with UrlPathHelper

use of org.springframework.web.util.UrlPathHelper in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMappingTests method handleMatchUriTemplateVariablesDecode.

// SPR-9098
@SuppressWarnings("unchecked")
@Test
public void handleMatchUriTemplateVariablesDecode() {
    RequestMappingInfo key = RequestMappingInfo.paths("/{group}/{identifier}").build();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb");
    UrlPathHelper pathHelper = new UrlPathHelper();
    pathHelper.setUrlDecode(false);
    String lookupPath = pathHelper.getLookupPathForRequest(request);
    this.handlerMapping.setUrlPathHelper(pathHelper);
    this.handlerMapping.handleMatch(key, lookupPath, request);
    String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
    Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);
    assertNotNull(uriVariables);
    assertEquals("group", uriVariables.get("group"));
    assertEquals("a/b", uriVariables.get("identifier"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test)

Aggregations

UrlPathHelper (org.springframework.web.util.UrlPathHelper)11 Test (org.junit.Test)6 PathMatcher (org.springframework.util.PathMatcher)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)3 AntPathMatcher (org.springframework.util.AntPathMatcher)3 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 MultiValueMap (org.springframework.util.MultiValueMap)2 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)2 ArrayList (java.util.ArrayList)1 ApplicationContext (org.springframework.context.ApplicationContext)1 LocaleContext (org.springframework.context.i18n.LocaleContext)1 SimpleTimeZoneAwareLocaleContext (org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext)1 TimeZoneAwareLocaleContext (org.springframework.context.i18n.TimeZoneAwareLocaleContext)1 StopWatch (org.springframework.util.StopWatch)1 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)1 LocaleContextResolver (org.springframework.web.servlet.LocaleContextResolver)1 LocaleResolver (org.springframework.web.servlet.LocaleResolver)1 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)1 ResourceUrlProvider (org.springframework.web.servlet.resource.ResourceUrlProvider)1