Search in sources :

Example 1 with WebSocketServerSockJsSession

use of org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession in project spring-framework by spring-projects.

the class SockJsWebSocketHandlerTests method getSubProtocolsNone.

@Test
public void getSubProtocolsNone() throws Exception {
    WebSocketHandler handler = new TextWebSocketHandler();
    TaskScheduler scheduler = mock(TaskScheduler.class);
    DefaultSockJsService service = new DefaultSockJsService(scheduler);
    WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
    SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
    assertNull(sockJsHandler.getSubProtocols());
}
Also used : WebSocketServerSockJsSession(org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TaskScheduler(org.springframework.scheduling.TaskScheduler) Test(org.junit.Test)

Example 2 with WebSocketServerSockJsSession

use of org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession in project spring-framework by spring-projects.

the class SockJsWebSocketHandlerTests method getSubProtocols.

@Test
public void getSubProtocols() throws Exception {
    SubscribableChannel channel = mock(SubscribableChannel.class);
    SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
    StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
    handler.addProtocolHandler(stompHandler);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    DefaultSockJsService service = new DefaultSockJsService(scheduler);
    WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
    SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
    assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
}
Also used : WebSocketServerSockJsSession(org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) StompSubProtocolHandler(org.springframework.web.socket.messaging.StompSubProtocolHandler) TaskScheduler(org.springframework.scheduling.TaskScheduler) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 3 with WebSocketServerSockJsSession

use of org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession in project spring-framework by spring-projects.

the class WebSocketTransportHandler method handleRequest.

@Override
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {
    WebSocketServerSockJsSession sockJsSession = (WebSocketServerSockJsSession) wsSession;
    try {
        wsHandler = new SockJsWebSocketHandler(getServiceConfig(), wsHandler, sockJsSession);
        this.handshakeHandler.doHandshake(request, response, wsHandler, sockJsSession.getAttributes());
    } catch (Throwable ex) {
        sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
        throw new SockJsTransportFailureException("WebSocket handshake failure", wsSession.getId(), ex);
    }
}
Also used : SockJsTransportFailureException(org.springframework.web.socket.sockjs.SockJsTransportFailureException) WebSocketServerSockJsSession(org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession)

Aggregations

WebSocketServerSockJsSession (org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession)3 Test (org.junit.Test)2 TaskScheduler (org.springframework.scheduling.TaskScheduler)2 SubProtocolWebSocketHandler (org.springframework.web.socket.messaging.SubProtocolWebSocketHandler)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)1 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)1 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)1 StompSubProtocolHandler (org.springframework.web.socket.messaging.StompSubProtocolHandler)1 SockJsTransportFailureException (org.springframework.web.socket.sockjs.SockJsTransportFailureException)1