Search in sources :

Example 1 with AbstractSockJsSession

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

the class HttpReceivingTransportHandlerTests method handleRequestAndExpectFailure.

private void handleRequestAndExpectFailure() throws Exception {
    resetResponse();
    WebSocketHandler wsHandler = mock(WebSocketHandler.class);
    AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);
    new XhrReceivingTransportHandler().handleRequest(this.request, this.response, wsHandler, session);
    assertEquals(500, this.servletResponse.getStatus());
    verifyNoMoreInteractions(wsHandler);
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig)

Example 2 with AbstractSockJsSession

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

the class HttpSendingTransportHandlerTests method handleRequestXhr.

@Test
public void handleRequestXhr() throws Exception {
    XhrPollingTransportHandler transportHandler = new XhrPollingTransportHandler();
    transportHandler.initialize(this.sockJsConfig);
    AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler, null);
    transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
    assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
    assertEquals("o\n", this.servletResponse.getContentAsString());
    assertFalse("Polling request should complete after open frame", this.servletRequest.isAsyncStarted());
    verify(this.webSocketHandler).afterConnectionEstablished(session);
    resetRequestAndResponse();
    transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
    assertTrue("Polling request should remain open", this.servletRequest.isAsyncStarted());
    verify(this.taskScheduler).schedule(any(Runnable.class), any(Date.class));
    resetRequestAndResponse();
    transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
    assertFalse("Request should have been rejected", this.servletRequest.isAsyncStarted());
    assertEquals("c[2010,\"Another connection still open\"]\n", this.servletResponse.getContentAsString());
}
Also used : AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) Date(java.util.Date) Test(org.junit.Test)

Example 3 with AbstractSockJsSession

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

the class HttpSendingTransportHandlerTests method handleRequestXhrStreaming.

@Test
public void handleRequestXhrStreaming() throws Exception {
    XhrStreamingTransportHandler transportHandler = new XhrStreamingTransportHandler();
    transportHandler.initialize(this.sockJsConfig);
    AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler, null);
    transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
    assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
    assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
    verify(this.webSocketHandler).afterConnectionEstablished(session);
}
Also used : AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) Test(org.junit.Test)

Example 4 with AbstractSockJsSession

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

the class HttpReceivingTransportHandlerTests method handleRequest.

private void handleRequest(AbstractHttpReceivingTransportHandler transportHandler) throws Exception {
    WebSocketHandler wsHandler = mock(WebSocketHandler.class);
    AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);
    transportHandler.initialize(new StubSockJsServiceConfig());
    transportHandler.handleRequest(this.request, this.response, wsHandler, session);
    assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString());
    verify(wsHandler).handleMessage(session, new TextMessage("x"));
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig) TextMessage(org.springframework.web.socket.TextMessage)

Aggregations

AbstractSockJsSession (org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession)4 Test (org.junit.Test)2 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)2 StubSockJsServiceConfig (org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig)2 TestHttpSockJsSession (org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession)2 Date (java.util.Date)1 TextMessage (org.springframework.web.socket.TextMessage)1