use of org.springframework.web.socket.CloseStatus in project spring-framework by spring-projects.
the class RestTemplateXhrTransport method connectInternal.
@Override
protected void connectInternal(final TransportRequest transportRequest, final WebSocketHandler handler, final URI receiveUrl, final HttpHeaders handshakeHeaders, final XhrClientSockJsSession session, final SettableListenableFuture<WebSocketSession> connectFuture) {
getTaskExecutor().execute(new Runnable() {
@Override
public void run() {
HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
XhrRequestCallback requestCallback = new XhrRequestCallback(handshakeHeaders);
XhrRequestCallback requestCallbackAfterHandshake = new XhrRequestCallback(httpHeaders);
XhrReceiveExtractor responseExtractor = new XhrReceiveExtractor(session);
while (true) {
if (session.isDisconnected()) {
session.afterTransportClosed(null);
break;
}
try {
if (logger.isTraceEnabled()) {
logger.trace("Starting XHR receive request, url=" + receiveUrl);
}
getRestTemplate().execute(receiveUrl, HttpMethod.POST, requestCallback, responseExtractor);
requestCallback = requestCallbackAfterHandshake;
} catch (Throwable ex) {
if (!connectFuture.isDone()) {
connectFuture.setException(ex);
} else {
session.handleTransportError(ex);
session.afterTransportClosed(new CloseStatus(1006, ex.getMessage()));
}
break;
}
}
}
});
}
use of org.springframework.web.socket.CloseStatus in project spring-framework by spring-projects.
the class ExceptionWebSocketHandlerDecoratorTests method afterConnectionClosed.
@Test
public void afterConnectionClosed() throws Exception {
CloseStatus closeStatus = CloseStatus.NORMAL;
willThrow(new IllegalStateException("error")).given(this.delegate).afterConnectionClosed(this.session, closeStatus);
this.decorator.afterConnectionClosed(this.session, closeStatus);
assertNull(this.session.getCloseStatus());
}
use of org.springframework.web.socket.CloseStatus in project spring-framework by spring-projects.
the class RestTemplateXhrTransportTests method connectReceiveAndCloseWithPrelude.
@Test
public void connectReceiveAndCloseWithPrelude() throws Exception {
StringBuilder sb = new StringBuilder(2048);
for (int i = 0; i < 2048; i++) {
sb.append('h');
}
String body = sb.toString() + "\n" + "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
ClientHttpResponse response = response(HttpStatus.OK, body);
connect(response);
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
verifyNoMoreInteractions(this.webSocketHandler);
}
use of org.springframework.web.socket.CloseStatus in project spring-framework by spring-projects.
the class RestTemplateXhrTransportTests method connectReceiveAndClose.
@Test
public void connectReceiveAndClose() throws Exception {
String body = "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
ClientHttpResponse response = response(HttpStatus.OK, body);
connect(response);
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
verifyNoMoreInteractions(this.webSocketHandler);
}
use of org.springframework.web.socket.CloseStatus in project spring-framework by spring-projects.
the class SockJsSessionTests method close.
@Test
public void close() throws Exception {
this.session.delegateConnectionEstablished();
assertOpen();
this.session.setActive(true);
this.session.close();
assertEquals(1, this.session.getSockJsFramesWritten().size());
assertEquals(SockJsFrame.closeFrameGoAway(), this.session.getSockJsFramesWritten().get(0));
assertEquals(1, this.session.getNumberOfLastActiveTimeUpdates());
assertTrue(this.session.didCancelHeartbeat());
assertEquals(new CloseStatus(3000, "Go away!"), this.session.getCloseStatus());
assertClosed();
verify(this.webSocketHandler).afterConnectionClosed(this.session, new CloseStatus(3000, "Go away!"));
}
Aggregations