Search in sources :

Example 16 with HttpRequestHandler

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

the class WebMvcStompWebSocketEndpointRegistrationTests method allowedOrigins.

@Test
public void allowedOrigins() {
    WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    registration.setAllowedOrigins();
    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) mappings.entrySet().iterator().next().getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertEquals(1, requestHandler.getHandshakeInterceptors().size());
    assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(0).getClass());
}
Also used : WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) Test(org.junit.Test)

Example 17 with HttpRequestHandler

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

the class WebMvcStompWebSocketEndpointRegistrationTests method allowedOriginsWithSockJsService.

@Test
public void allowedOriginsWithSockJsService() {
    WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    String origin = "http://mydomain.com";
    registration.setAllowedOrigins(origin).withSockJS();
    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) mappings.entrySet().iterator().next().getKey();
    assertNotNull(requestHandler.getSockJsService());
    DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
    assertTrue(sockJsService.getAllowedOrigins().contains(origin));
    assertFalse(sockJsService.shouldSuppressCors());
    registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    registration.withSockJS().setAllowedOrigins(origin);
    mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    requestHandler = (SockJsHttpRequestHandler) mappings.entrySet().iterator().next().getKey();
    assertNotNull(requestHandler.getSockJsService());
    sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
    assertTrue(sockJsService.getAllowedOrigins().contains(origin));
    assertFalse(sockJsService.shouldSuppressCors());
}
Also used : SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) DefaultSockJsService(org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService) Test(org.junit.Test)

Example 18 with HttpRequestHandler

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

the class WebMvcStompWebSocketEndpointRegistrationTests method sameOrigin.

@Test
public void sameOrigin() {
    WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    registration.setAllowedOrigins();
    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) mappings.entrySet().iterator().next().getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertEquals(1, requestHandler.getHandshakeInterceptors().size());
    assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(0).getClass());
}
Also used : WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) Test(org.junit.Test)

Example 19 with HttpRequestHandler

use of org.springframework.web.HttpRequestHandler in project spring-security by spring-projects.

the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method messagesConnectWebSocketUseCsrfTokenHandshakeInterceptor.

@Test
public void messagesConnectWebSocketUseCsrfTokenHandshakeInterceptor() throws Exception {
    loadConfig(WebSocketSecurityConfig.class);
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
    Message<?> message = message(headers, "/authentication");
    MockHttpServletRequest request = websocketHttpRequest("/websocket");
    HttpRequestHandler handler = handler(request);
    handler.handleRequest(request, new MockHttpServletResponse());
    assertHandshake(request);
}
Also used : HttpRequestHandler(org.springframework.web.HttpRequestHandler) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Aggregations

HttpRequestHandler (org.springframework.web.HttpRequestHandler)19 Test (org.junit.Test)14 WebSocketHttpRequestHandler (org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)11 SockJsHttpRequestHandler (org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler)11 DefaultSockJsService (org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService)5 List (java.util.List)4 Map (java.util.Map)4 MultiValueMap (org.springframework.util.MultiValueMap)4 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)4 LinkedHashMap (java.util.LinkedHashMap)3 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)3 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)3 WebSocketTransportHandler (org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler)3 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 MessageHandler (org.springframework.messaging.MessageHandler)2 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)2 SimpleBrokerMessageHandler (org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)2