Search in sources :

Example 11 with SimpleUrlHandlerMapping

use of org.springframework.web.servlet.handler.SimpleUrlHandlerMapping in project spring-framework by spring-projects.

the class MvcNamespaceTests method testResourcesWithOptionalAttributes.

@Test
public void testResourcesWithOptionalAttributes() throws Exception {
    loadBeanDefinitions("mvc-config-resources-optional-attrs.xml", 10);
    SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
    assertNotNull(mapping);
    assertEquals(5, mapping.getOrder());
    assertNotNull(mapping.getUrlMap().get("/resources/**"));
    ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"), ResourceHttpRequestHandler.class);
    assertNotNull(handler);
    assertEquals(3600, handler.getCacheSeconds());
}
Also used : ResourceHttpRequestHandler(org.springframework.web.servlet.resource.ResourceHttpRequestHandler) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) Test(org.junit.Test)

Example 12 with SimpleUrlHandlerMapping

use of org.springframework.web.servlet.handler.SimpleUrlHandlerMapping in project spring-framework by spring-projects.

the class MvcNamespaceTests method testViewControllersDefaultConfig.

@Test
public void testViewControllersDefaultConfig() {
    loadBeanDefinitions("mvc-config-view-controllers-minimal.xml", 7);
    SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class);
    assertNotNull(hm);
    ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path");
    assertNotNull(viewController);
    assertEquals("home", viewController.getViewName());
    ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
    assertNotNull(redirectViewController);
    assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class));
    ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
    assertNotNull(statusViewController);
    assertEquals(404, statusViewController.getStatusCode().value());
    BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
    assertNotNull(beanNameMapping);
    assertEquals(2, beanNameMapping.getOrder());
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) BeanNameUrlHandlerMapping(org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping) RedirectView(org.springframework.web.servlet.view.RedirectView) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) Test(org.junit.Test)

Example 13 with SimpleUrlHandlerMapping

use of org.springframework.web.servlet.handler.SimpleUrlHandlerMapping 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 14 with SimpleUrlHandlerMapping

use of org.springframework.web.servlet.handler.SimpleUrlHandlerMapping in project spring-framework by spring-projects.

the class TestMessageCodec method webSocketHandlersAttributes.

@Test
@SuppressWarnings("unchecked")
public void webSocketHandlersAttributes() {
    loadBeanDefinitions("websocket-config-handlers-attributes.xml");
    HandlerMapping handlerMapping = this.appContext.getBean(HandlerMapping.class);
    assertNotNull(handlerMapping);
    assertTrue(handlerMapping instanceof SimpleUrlHandlerMapping);
    SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
    assertEquals(2, urlHandlerMapping.getOrder());
    WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/foo");
    assertNotNull(handler);
    unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
    HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
    assertNotNull(handshakeHandler);
    assertTrue(handshakeHandler instanceof TestHandshakeHandler);
    List<HandshakeInterceptor> interceptors = handler.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class), instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
    handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/test");
    assertNotNull(handler);
    unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
    handshakeHandler = handler.getHandshakeHandler();
    assertNotNull(handshakeHandler);
    assertTrue(handshakeHandler instanceof TestHandshakeHandler);
    interceptors = handler.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class), instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
}
Also used : HandshakeHandler(org.springframework.web.socket.server.HandshakeHandler) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) HandlerMapping(org.springframework.web.servlet.HandlerMapping) HandshakeInterceptor(org.springframework.web.socket.server.HandshakeInterceptor) OriginHandshakeInterceptor(org.springframework.web.socket.server.support.OriginHandshakeInterceptor) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) Test(org.junit.Test)

Example 15 with SimpleUrlHandlerMapping

use of org.springframework.web.servlet.handler.SimpleUrlHandlerMapping in project spring-framework by spring-projects.

the class TestMessageCodec method sockJs.

@Test
@SuppressWarnings("unchecked")
public void sockJs() {
    loadBeanDefinitions("websocket-config-handlers-sockjs.xml");
    SimpleUrlHandlerMapping handlerMapping = this.appContext.getBean(SimpleUrlHandlerMapping.class);
    assertNotNull(handlerMapping);
    SockJsHttpRequestHandler testHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
    assertNotNull(testHandler);
    unwrapAndCheckDecoratedHandlerType(testHandler.getWebSocketHandler(), TestWebSocketHandler.class);
    SockJsService testSockJsService = testHandler.getSockJsService();
    SockJsHttpRequestHandler fooHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/foo/**");
    assertNotNull(fooHandler);
    unwrapAndCheckDecoratedHandlerType(fooHandler.getWebSocketHandler(), FooWebSocketHandler.class);
    SockJsService sockJsService = fooHandler.getSockJsService();
    assertNotNull(sockJsService);
    assertSame(testSockJsService, sockJsService);
    assertThat(sockJsService, instanceOf(DefaultSockJsService.class));
    DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService;
    assertThat(defaultSockJsService.getTaskScheduler(), instanceOf(ThreadPoolTaskScheduler.class));
    assertFalse(defaultSockJsService.shouldSuppressCors());
    Map<TransportType, TransportHandler> transportHandlers = defaultSockJsService.getTransportHandlers();
    assertThat(transportHandlers.values(), containsInAnyOrder(instanceOf(XhrPollingTransportHandler.class), instanceOf(XhrReceivingTransportHandler.class), instanceOf(JsonpPollingTransportHandler.class), instanceOf(JsonpReceivingTransportHandler.class), instanceOf(XhrStreamingTransportHandler.class), instanceOf(EventSourceTransportHandler.class), instanceOf(HtmlFileTransportHandler.class), instanceOf(WebSocketTransportHandler.class)));
    WebSocketTransportHandler handler = (WebSocketTransportHandler) transportHandlers.get(TransportType.WEBSOCKET);
    assertEquals(TestHandshakeHandler.class, handler.getHandshakeHandler().getClass());
    List<HandshakeInterceptor> interceptors = defaultSockJsService.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class), instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
}
Also used : JsonpReceivingTransportHandler(org.springframework.web.socket.sockjs.transport.handler.JsonpReceivingTransportHandler) HtmlFileTransportHandler(org.springframework.web.socket.sockjs.transport.handler.HtmlFileTransportHandler) TransportHandler(org.springframework.web.socket.sockjs.transport.TransportHandler) XhrStreamingTransportHandler(org.springframework.web.socket.sockjs.transport.handler.XhrStreamingTransportHandler) XhrPollingTransportHandler(org.springframework.web.socket.sockjs.transport.handler.XhrPollingTransportHandler) EventSourceTransportHandler(org.springframework.web.socket.sockjs.transport.handler.EventSourceTransportHandler) XhrReceivingTransportHandler(org.springframework.web.socket.sockjs.transport.handler.XhrReceivingTransportHandler) JsonpPollingTransportHandler(org.springframework.web.socket.sockjs.transport.handler.JsonpPollingTransportHandler) WebSocketTransportHandler(org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) TransportHandlingSockJsService(org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService) SockJsService(org.springframework.web.socket.sockjs.SockJsService) DefaultSockJsService(org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService) DefaultSockJsService(org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService) TransportType(org.springframework.web.socket.sockjs.transport.TransportType) HandshakeInterceptor(org.springframework.web.socket.server.HandshakeInterceptor) OriginHandshakeInterceptor(org.springframework.web.socket.server.support.OriginHandshakeInterceptor) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) WebSocketTransportHandler(org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler) Test(org.junit.Test)

Aggregations

SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)36 Test (org.junit.Test)25 ResourceHttpRequestHandler (org.springframework.web.servlet.resource.ResourceHttpRequestHandler)9 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)8 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)7 WebSocketHttpRequestHandler (org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)6 Map (java.util.Map)5 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)5 HandlerMapping (org.springframework.web.servlet.HandlerMapping)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 DefaultServletHttpRequestHandler (org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler)5 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)5 OriginHandshakeInterceptor (org.springframework.web.socket.server.support.OriginHandshakeInterceptor)5 SockJsHttpRequestHandler (org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler)5 LinkedHashMap (java.util.LinkedHashMap)3 HttpRequestHandler (org.springframework.web.HttpRequestHandler)3 ParameterizableViewController (org.springframework.web.servlet.mvc.ParameterizableViewController)3 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2