use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class AbstractUrlHandlerMapping method buildPathExposingHandler.
/**
* Build a handler object for the given raw handler, exposing the actual
* handler, the {@link #PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE}, as well as
* the {@link #URI_TEMPLATE_VARIABLES_ATTRIBUTE} before executing the handler.
* <p>The default implementation builds a {@link HandlerExecutionChain}
* with a special interceptor that exposes the path attribute and uri template variables
* @param rawHandler the raw handler to expose
* @param pathWithinMapping the path to expose before executing the handler
* @param uriTemplateVariables the URI template variables, can be {@code null} if no variables found
* @return the final handler object
*/
protected Object buildPathExposingHandler(Object rawHandler, String bestMatchingPattern, String pathWithinMapping, Map<String, String> uriTemplateVariables) {
HandlerExecutionChain chain = new HandlerExecutionChain(rawHandler);
chain.addInterceptor(new PathExposingHandlerInterceptor(bestMatchingPattern, pathWithinMapping));
if (!CollectionUtils.isEmpty(uriTemplateVariables)) {
chain.addInterceptor(new UriTemplateVariablesHandlerInterceptor(uriTemplateVariables));
}
return chain;
}
use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class MvcNamespaceTests method testViewControllersOnWebSphere.
/** WebSphere gives trailing servlet path slashes by default!! */
@Test
public void testViewControllersOnWebSphere() throws Exception {
loadBeanDefinitions("mvc-config-view-controllers.xml", 19);
SimpleUrlHandlerMapping mapping2 = appContext.getBean(SimpleUrlHandlerMapping.class);
SimpleControllerHandlerAdapter adapter = appContext.getBean(SimpleControllerHandlerAdapter.class);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
request.setRequestURI("/myapp/app/bar");
request.setContextPath("/myapp");
request.setServletPath("/app/");
request.setAttribute("com.ibm.websphere.servlet.uri_non_decoded", "/myapp/app/bar");
HandlerExecutionChain chain = mapping2.getHandler(request);
assertEquals(4, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[1] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
ModelAndView mv2 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertEquals("baz", mv2.getViewName());
request.setRequestURI("/myapp/app/");
request.setContextPath("/myapp");
request.setServletPath("/app/");
chain = mapping2.getHandler(request);
assertEquals(4, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[1] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
ModelAndView mv3 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertEquals("root", mv3.getViewName());
request.setRequestURI("/myapp/");
request.setContextPath("/myapp");
request.setServletPath("/");
chain = mapping2.getHandler(request);
assertEquals(4, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[1] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
mv3 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertEquals("root", mv3.getViewName());
}
use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class MvcNamespaceTests method testDefaultServletHandler.
@Test
public void testDefaultServletHandler() throws Exception {
loadBeanDefinitions("mvc-config-default-servlet.xml", 6);
HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
assertNotNull(adapter);
DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
assertNotNull(handler);
SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
assertNotNull(mapping);
assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/foo.css");
request.setMethod("GET");
HandlerExecutionChain chain = mapping.getHandler(request);
assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = adapter.handle(request, response, chain.getHandler());
assertNull(mv);
}
use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method requestMappingHandlerMapping.
@Test
public void requestMappingHandlerMapping() throws Exception {
ApplicationContext context = initContext(WebConfig.class, ScopedController.class, ScopedProxyController.class);
RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class);
assertEquals(0, handlerMapping.getOrder());
HandlerExecutionChain chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/"));
assertNotNull(chain);
assertNotNull(chain.getInterceptors());
assertEquals(ConversionServiceExposingInterceptor.class, chain.getInterceptors()[0].getClass());
chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/scoped"));
assertNotNull("HandlerExecutionChain for '/scoped' mapping should not be null.", chain);
chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/scopedProxy"));
assertNotNull("HandlerExecutionChain for '/scopedProxy' mapping should not be null.", chain);
}
use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method beanNameHandlerMapping.
@Test
public void beanNameHandlerMapping() throws Exception {
ApplicationContext context = initContext(WebConfig.class);
BeanNameUrlHandlerMapping handlerMapping = context.getBean(BeanNameUrlHandlerMapping.class);
assertEquals(2, handlerMapping.getOrder());
HttpServletRequest request = new MockHttpServletRequest("GET", "/testController");
HandlerExecutionChain chain = handlerMapping.getHandler(request);
assertNotNull(chain);
assertNotNull(chain.getInterceptors());
assertEquals(3, chain.getInterceptors().length);
assertEquals(ConversionServiceExposingInterceptor.class, chain.getInterceptors()[1].getClass());
assertEquals(ResourceUrlProviderExposingInterceptor.class, chain.getInterceptors()[2].getClass());
}
Aggregations