Search in sources :

Example 11 with RequestMappingHandlerMapping

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

the class MvcNamespaceTests method doTestCustomValidator.

private void doTestCustomValidator(String xml) throws Exception {
    loadBeanDefinitions(xml, 14);
    RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
    assertNotNull(mapping);
    assertFalse(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
    RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
    assertNotNull(adapter);
    assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
    // default web binding initializer behavior test
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("date", "2009-10-31");
    MockHttpServletResponse response = new MockHttpServletResponse();
    adapter.handle(request, response, handlerMethod);
    assertTrue(appContext.getBean(TestValidator.class).validatorInvoked);
    assertFalse(handler.recordedValidationError);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Example 12 with RequestMappingHandlerMapping

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

the class MvcNamespaceTests method testPathMatchingHandlerMappings.

@Test
public void testPathMatchingHandlerMappings() throws Exception {
    loadBeanDefinitions("mvc-config-path-matching-mappings.xml", 23);
    RequestMappingHandlerMapping requestMapping = appContext.getBean(RequestMappingHandlerMapping.class);
    assertNotNull(requestMapping);
    assertEquals(TestPathHelper.class, requestMapping.getUrlPathHelper().getClass());
    assertEquals(TestPathMatcher.class, requestMapping.getPathMatcher().getClass());
    SimpleUrlHandlerMapping viewController = appContext.getBean(VIEWCONTROLLER_BEAN_NAME, SimpleUrlHandlerMapping.class);
    assertNotNull(viewController);
    assertEquals(TestPathHelper.class, viewController.getUrlPathHelper().getClass());
    assertEquals(TestPathMatcher.class, viewController.getPathMatcher().getClass());
    for (SimpleUrlHandlerMapping handlerMapping : appContext.getBeansOfType(SimpleUrlHandlerMapping.class).values()) {
        assertNotNull(handlerMapping);
        assertEquals(TestPathHelper.class, handlerMapping.getUrlPathHelper().getClass());
        assertEquals(TestPathMatcher.class, handlerMapping.getPathMatcher().getClass());
    }
}
Also used : RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) Test(org.junit.Test)

Example 13 with RequestMappingHandlerMapping

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping in project Activiti by Activiti.

the class DispatcherServletConfiguration method requestMappingHandlerMapping.

@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
    log.debug("Creating requestMappingHandlerMapping");
    RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();
    requestMappingHandlerMapping.setUseSuffixPatternMatch(false);
    Object[] interceptors = { localeChangeInterceptor() };
    requestMappingHandlerMapping.setInterceptors(interceptors);
    return requestMappingHandlerMapping;
}
Also used : RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) Bean(org.springframework.context.annotation.Bean)

Example 14 with RequestMappingHandlerMapping

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping in project spring-mvc-31-demo by rstoyanchev.

the class WebConfig method requestMappingHandlerMapping.

// Configuration for custom @RequestMapping condition
// See ~.requestcondition package
@Override
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
    RequestMappingHandlerMapping handlerMapping = new ExtendedRequestMappingHandlerMapping();
    handlerMapping.setOrder(0);
    handlerMapping.setInterceptors(getInterceptors());
    return handlerMapping;
}
Also used : ExtendedRequestMappingHandlerMapping(org.springframework.samples.mvc31.requestcondition.mvc.ExtendedRequestMappingHandlerMapping) ExtendedRequestMappingHandlerMapping(org.springframework.samples.mvc31.requestcondition.mvc.ExtendedRequestMappingHandlerMapping) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) Bean(org.springframework.context.annotation.Bean)

Example 15 with RequestMappingHandlerMapping

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping 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)

Aggregations

RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)25 Test (org.junit.Test)17 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)13 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)11 Bean (org.springframework.context.annotation.Bean)6 ConversionServiceExposingInterceptor (org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor)6 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)5 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)4 NativeWebRequest (org.springframework.web.context.request.NativeWebRequest)4 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)4 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)4 LocaleChangeInterceptor (org.springframework.web.servlet.i18n.LocaleChangeInterceptor)4 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)4 ThemeChangeInterceptor (org.springframework.web.servlet.theme.ThemeChangeInterceptor)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 PathMatcher (org.springframework.util.PathMatcher)3 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)3 HandlerMethod (org.springframework.web.method.HandlerMethod)3 HandlerInterceptor (org.springframework.web.servlet.HandlerInterceptor)3 UrlPathHelper (org.springframework.web.util.UrlPathHelper)3