Search in sources :

Example 41 with WebSocketHandler

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

the class WebSocketStompClientTests method connect.

private WebSocketHandler connect() {
    this.stompClient.connect("/foo", mock(StompSessionHandler.class));
    verify(this.stompSession).getSessionFuture();
    verifyNoMoreInteractions(this.stompSession);
    WebSocketHandler webSocketHandler = this.webSocketHandlerCaptor.getValue();
    assertNotNull(webSocketHandler);
    return webSocketHandler;
}
Also used : StompSessionHandler(org.springframework.messaging.simp.stomp.StompSessionHandler) WebSocketHandler(org.springframework.web.socket.WebSocketHandler)

Example 42 with WebSocketHandler

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

the class DefaultHandshakeHandlerTests method subProtocolCapableHandlerNoMatch.

@Test
public void subProtocolCapableHandlerNoMatch() throws Exception {
    given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] { "13" });
    this.servletRequest.setMethod("GET");
    WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
    headers.setUpgrade("WebSocket");
    headers.setConnection("Upgrade");
    headers.setSecWebSocketVersion("13");
    headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
    headers.setSecWebSocketProtocol("v10.stomp");
    WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
    Map<String, Object> attributes = Collections.<String, Object>emptyMap();
    this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
    verify(this.upgradeStrategy).upgrade(this.request, this.response, null, Collections.<WebSocketExtension>emptyList(), null, handler, attributes);
}
Also used : WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) Test(org.junit.Test)

Example 43 with WebSocketHandler

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

the class DefaultHandshakeHandlerTests method subProtocolCapableHandler.

@Test
public void subProtocolCapableHandler() throws Exception {
    given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] { "13" });
    this.servletRequest.setMethod("GET");
    WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
    headers.setUpgrade("WebSocket");
    headers.setConnection("Upgrade");
    headers.setSecWebSocketVersion("13");
    headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
    headers.setSecWebSocketProtocol("v11.stomp");
    WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
    Map<String, Object> attributes = Collections.<String, Object>emptyMap();
    this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
    verify(this.upgradeStrategy).upgrade(this.request, this.response, "v11.stomp", Collections.<WebSocketExtension>emptyList(), null, handler, attributes);
}
Also used : WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) Test(org.junit.Test)

Example 44 with WebSocketHandler

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

the class DefaultHandshakeHandlerTests method supportedExtensions.

@Test
public void supportedExtensions() throws Exception {
    WebSocketExtension extension1 = new WebSocketExtension("ext1");
    WebSocketExtension extension2 = new WebSocketExtension("ext2");
    given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] { "13" });
    given(this.upgradeStrategy.getSupportedExtensions(this.request)).willReturn(Arrays.asList(extension1));
    this.servletRequest.setMethod("GET");
    WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
    headers.setUpgrade("WebSocket");
    headers.setConnection("Upgrade");
    headers.setSecWebSocketVersion("13");
    headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
    headers.setSecWebSocketExtensions(Arrays.asList(extension1, extension2));
    WebSocketHandler handler = new TextWebSocketHandler();
    Map<String, Object> attributes = Collections.<String, Object>emptyMap();
    this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
    verify(this.upgradeStrategy).upgrade(this.request, this.response, null, Arrays.asList(extension1), null, handler, attributes);
}
Also used : WebSocketExtension(org.springframework.web.socket.WebSocketExtension) WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) Test(org.junit.Test)

Aggregations

WebSocketHandler (org.springframework.web.socket.WebSocketHandler)44 Test (org.junit.Test)36 HashMap (java.util.HashMap)14 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)14 WebSocketHttpHeaders (org.springframework.web.socket.WebSocketHttpHeaders)5 SubProtocolWebSocketHandler (org.springframework.web.socket.messaging.SubProtocolWebSocketHandler)5 MockHttpSession (org.springframework.mock.web.test.MockHttpSession)4 TextMessage (org.springframework.web.socket.TextMessage)4 HandshakeHandler (org.springframework.web.socket.server.HandshakeHandler)4 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)4 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)3 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)3 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)3 URI (java.net.URI)2 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 StompBrokerRelayMessageHandler (org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler)2 DefaultUserDestinationResolver (org.springframework.messaging.simp.user.DefaultUserDestinationResolver)2