@Test public void fallbackAfterTransportFailure() throws Exception { this.testFilter.sendErrorMap.put("/websocket", 200); this.testFilter.sendErrorMap.put("/xhr_streaming", 500); TestClientHandler handler = new TestClientHandler(); initSockJsClient(createWebSocketTransport(), createXhrTransport()); WebSocketSession session = this.sockJsClient.doHandshake(handler, this.baseUrl + "/echo").get(); assertEquals("Fallback didn't occur", XhrClientSockJsSession.class, session.getClass()); TextMessage message = new TextMessage("message1"); session.sendMessage(message); handler.awaitMessage(message, 5000); }
private void testReceiveOneMessage(Transport transport, WebSocketHttpHeaders headers) throws Exception { TestClientHandler clientHandler = new TestClientHandler(); initSockJsClient(transport); this.sockJsClient.doHandshake(clientHandler, headers, new URI(this.baseUrl + "/test")).get(); TestServerHandler serverHandler = this.wac.getBean(TestServerHandler.class); assertNotNull("afterConnectionEstablished should have been called", clientHandler.session); serverHandler.awaitSession(5000); TextMessage message = new TextMessage("message1"); serverHandler.session.sendMessage(message); clientHandler.awaitMessage(message, 5000); }
@Test(timeout = 5000) public void fallbackAfterConnectTimeout() throws Exception { TestClientHandler clientHandler = new TestClientHandler(); this.testFilter.sleepDelayMap.put("/xhr_streaming", 10000L); this.testFilter.sendErrorMap.put("/xhr_streaming", 503); initSockJsClient(createXhrTransport()); this.sockJsClient.setConnectTimeoutScheduler(this.wac.getBean(ThreadPoolTaskScheduler.class)); WebSocketSession clientSession = sockJsClient.doHandshake(clientHandler, this.baseUrl + "/echo").get(); assertEquals("Fallback didn't occur", XhrClientSockJsSession.class, clientSession.getClass()); TextMessage message = new TextMessage("message1"); clientSession.sendMessage(message); clientHandler.awaitMessage(message, 5000); clientSession.close(); }