Search in sources :

Example 1 with HttpSessionHandshakeInterceptor

use of org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor in project spring-framework by spring-projects.

the class WebSocketHandlerRegistrationTests method interceptors.

@Test
public void interceptors() {
    WebSocketHandler handler = new TextWebSocketHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    this.registration.addHandler(handler, "/foo").addInterceptors(interceptor);
    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(1, mappings.size());
    Mapping mapping = mappings.get(0);
    assertEquals(handler, mapping.webSocketHandler);
    assertEquals("/foo", mapping.path);
    assertEquals(2, mapping.interceptors.length);
    assertEquals(interceptor, mapping.interceptors[0]);
    assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) Test(org.junit.Test)

Example 2 with HttpSessionHandshakeInterceptor

use of org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor in project spring-framework by spring-projects.

the class WebSocketHandlerRegistrationTests method emptyAllowedOrigin.

@Test
public void emptyAllowedOrigin() {
    WebSocketHandler handler = new TextWebSocketHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins();
    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(1, mappings.size());
    Mapping mapping = mappings.get(0);
    assertEquals(handler, mapping.webSocketHandler);
    assertEquals("/foo", mapping.path);
    assertEquals(2, mapping.interceptors.length);
    assertEquals(interceptor, mapping.interceptors[0]);
    assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) Test(org.junit.Test)

Example 3 with HttpSessionHandshakeInterceptor

use of org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor in project spring-framework by spring-projects.

the class WebSocketHandlerRegistrationTests method interceptorsPassedToSockJsRegistration.

@Test
public void interceptorsPassedToSockJsRegistration() {
    WebSocketHandler handler = new TextWebSocketHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins("http://mydomain1.com").withSockJS();
    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(1, mappings.size());
    Mapping mapping = mappings.get(0);
    assertEquals(handler, mapping.webSocketHandler);
    assertEquals("/foo/**", mapping.path);
    assertNotNull(mapping.sockJsService);
    assertTrue(mapping.sockJsService.getAllowedOrigins().contains("http://mydomain1.com"));
    List<HandshakeInterceptor> interceptors = mapping.sockJsService.getHandshakeInterceptors();
    assertEquals(interceptor, interceptors.get(0));
    assertEquals(OriginHandshakeInterceptor.class, interceptors.get(1).getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) HandshakeInterceptor(org.springframework.web.socket.server.HandshakeInterceptor) HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) OriginHandshakeInterceptor(org.springframework.web.socket.server.support.OriginHandshakeInterceptor) Test(org.junit.Test)

Example 4 with HttpSessionHandshakeInterceptor

use of org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor in project spring-framework by spring-projects.

the class WebMvcStompWebSocketEndpointRegistrationTests method handshakeHandlerAndInterceptorWithAllowedOrigins.

@Test
public void handshakeHandlerAndInterceptorWithAllowedOrigins() {
    WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    String origin = "http://mydomain.com";
    registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin);
    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
    assertEquals(Arrays.asList("/foo"), entry.getValue());
    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertSame(handshakeHandler, requestHandler.getHandshakeHandler());
    assertEquals(2, requestHandler.getHandshakeInterceptors().size());
    assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0));
    assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) List(java.util.List) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) Test(org.junit.Test)

Example 5 with HttpSessionHandshakeInterceptor

use of org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor in project spring-framework by spring-projects.

the class WebMvcStompWebSocketEndpointRegistrationTests method handshakeHandlerAndInterceptor.

@Test
public void handshakeHandlerAndInterceptor() {
    WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor);
    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
    assertEquals(Arrays.asList("/foo"), entry.getValue());
    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertSame(handshakeHandler, requestHandler.getHandshakeHandler());
    assertEquals(2, requestHandler.getHandshakeInterceptors().size());
    assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0));
    assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) List(java.util.List) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)8 List (java.util.List)4 Map (java.util.Map)4 MultiValueMap (org.springframework.util.MultiValueMap)4 HttpRequestHandler (org.springframework.web.HttpRequestHandler)4 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)4 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)4 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)4 WebSocketHttpRequestHandler (org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)4 SockJsHttpRequestHandler (org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler)4 TransportHandler (org.springframework.web.socket.sockjs.transport.TransportHandler)2 TransportType (org.springframework.web.socket.sockjs.transport.TransportType)2 DefaultSockJsService (org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService)2 WebSocketTransportHandler (org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler)2 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)1 OriginHandshakeInterceptor (org.springframework.web.socket.server.support.OriginHandshakeInterceptor)1