use of org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler in project spring-framework by spring-projects.
the class DefaultServletHandlerConfigurer method enable.
/**
* Enable forwarding to the "default" Servlet identified by the given name.
* This is useful when the default Servlet cannot be auto-detected, for example when it has been manually configured.
* @see DefaultServletHttpRequestHandler
*/
public void enable(String defaultServletName) {
handler = new DefaultServletHttpRequestHandler();
handler.setDefaultServletName(defaultServletName);
handler.setServletContext(servletContext);
}
use of org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler in project spring-framework by spring-projects.
the class DefaultServletHandlerConfigurer method getHandlerMapping.
/**
* Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
* {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; or {@code null} if
* default servlet handling was not been enabled.
*/
protected AbstractHandlerMapping getHandlerMapping() {
if (handler == null) {
return null;
}
Map<String, HttpRequestHandler> urlMap = new HashMap<>();
urlMap.put("/**", handler);
SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
handlerMapping.setOrder(Integer.MAX_VALUE);
handlerMapping.setUrlMap(urlMap);
return handlerMapping;
}
use of org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler in project spring-framework by spring-projects.
the class MvcNamespaceTests method testDefaultServletHandlerWithOptionalAttributes.
@Test
public void testDefaultServletHandlerWithOptionalAttributes() throws Exception {
loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.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.resource.DefaultServletHttpRequestHandler in project spring-framework by spring-projects.
the class DefaultServletHandlerConfigurerTests method enableWithServletName.
@Test
public void enableWithServletName() throws Exception {
configurer.enable("defaultServlet");
SimpleUrlHandlerMapping handlerMapping = getHandlerMapping();
DefaultServletHttpRequestHandler handler = (DefaultServletHttpRequestHandler) handlerMapping.getUrlMap().get("/**");
assertNotNull(handler);
assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());
handler.handleRequest(new MockHttpServletRequest(), response);
String expected = "defaultServlet";
assertEquals("The ServletContext was not called with the default servlet name", expected, servletContext.url);
assertEquals("The request was not forwarded", expected, response.getForwardedUrl());
}
use of org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler in project spring-framework by spring-projects.
the class DefaultServletHandlerConfigurerTests method enable.
@Test
public void enable() throws Exception {
configurer.enable();
SimpleUrlHandlerMapping getHandlerMapping = getHandlerMapping();
SimpleUrlHandlerMapping handlerMapping = getHandlerMapping;
DefaultServletHttpRequestHandler handler = (DefaultServletHttpRequestHandler) handlerMapping.getUrlMap().get("/**");
assertNotNull(handler);
assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());
handler.handleRequest(new MockHttpServletRequest(), response);
String expected = "default";
assertEquals("The ServletContext was not called with the default servlet name", expected, servletContext.url);
assertEquals("The request was not forwarded", expected, response.getForwardedUrl());
}
Aggregations