org.springframework.web.socket.sockjs.SockJsTransportFailureException Java Examples
The following examples show how to use
org.springframework.web.socket.sockjs.SockJsTransportFailureException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyXhrTransport.java From spring-analysis-note with MIT License | 6 votes |
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, @Nullable String body) { Request httpRequest = this.httpClient.newRequest(url).method(method); addHttpHeaders(httpRequest, headers); if (body != null) { httpRequest.content(new StringContentProvider(body)); } ContentResponse response; try { response = httpRequest.send(); } catch (Exception ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } HttpStatus status = HttpStatus.valueOf(response.getStatus()); HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders()); return (response.getContent() != null ? new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) : new ResponseEntity<>(responseHeaders, status)); }
Example #2
Source File: JettyXhrTransport.java From spring4-understanding with Apache License 2.0 | 6 votes |
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body) { Request httpRequest = this.httpClient.newRequest(url).method(method); addHttpHeaders(httpRequest, headers); if (body != null) { httpRequest.content(new StringContentProvider(body)); } ContentResponse response; try { response = httpRequest.send(); } catch (Exception ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } HttpStatus status = HttpStatus.valueOf(response.getStatus()); HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders()); return (response.getContent() != null ? new ResponseEntity<String>(response.getContentAsString(), responseHeaders, status) : new ResponseEntity<String>(responseHeaders, status)); }
Example #3
Source File: HtmlFileTransportHandler.java From java-technology-stack with MIT License | 6 votes |
@Override public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, AbstractHttpSockJsSession sockJsSession) throws SockJsException { String callback = getCallbackParam(request); if (!StringUtils.hasText(callback)) { response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); try { response.getBody().write("\"callback\" parameter required".getBytes(StandardCharsets.UTF_8)); } catch (IOException ex) { sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex); } return; } super.handleRequestInternal(request, response, sockJsSession); }
Example #4
Source File: StreamingSockJsSession.java From java-technology-stack with MIT License | 6 votes |
@Override protected void flushCache() throws SockJsTransportFailureException { while (!getMessageCache().isEmpty()) { String message = getMessageCache().poll(); SockJsMessageCodec messageCodec = getSockJsServiceConfig().getMessageCodec(); SockJsFrame frame = SockJsFrame.messageFrame(messageCodec, message); writeFrame(frame); this.byteCount += (frame.getContentBytes().length + 1); if (logger.isTraceEnabled()) { logger.trace(this.byteCount + " bytes written so far, " + getMessageCache().size() + " more messages not flushed"); } if (this.byteCount >= getSockJsServiceConfig().getStreamBytesLimit()) { logger.trace("Streamed bytes limit reached, recycling current request"); resetRequest(); this.byteCount = 0; break; } } scheduleHeartbeat(); }
Example #5
Source File: WebSocketServerSockJsSession.java From java-technology-stack with MIT License | 6 votes |
@Override public void sendMessageInternal(String message) throws SockJsTransportFailureException { // Open frame not sent yet? // If in the session initialization thread, then cache, otherwise wait. if (!this.openFrameSent) { synchronized (this.initSessionLock) { if (!this.openFrameSent) { this.initSessionCache.add(message); return; } } } cancelHeartbeat(); writeFrame(SockJsFrame.messageFrame(getMessageCodec(), message)); scheduleHeartbeat(); }
Example #6
Source File: AbstractSockJsSession.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * For internal use within a TransportHandler and the (TransportHandler-specific) * session class. */ protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureException { if (logger.isTraceEnabled()) { logger.trace("Preparing to write " + frame); } try { writeFrameInternal(frame); } catch (Throwable ex) { logWriteFrameFailure(ex); try { // Force disconnect (so we won't try to send close frame) disconnect(CloseStatus.SERVER_ERROR); } catch (Throwable disconnectFailure) { // Ignore } try { close(CloseStatus.SERVER_ERROR); } catch (Throwable closeFailure) { // Nothing of consequence, already forced disconnect } throw new SockJsTransportFailureException("Failed to write " + frame, getId(), ex); } }
Example #7
Source File: AbstractHttpSockJsSession.java From java-technology-stack with MIT License | 6 votes |
@Override protected final void sendMessageInternal(String message) throws SockJsTransportFailureException { synchronized (this.responseLock) { this.messageCache.add(message); if (logger.isTraceEnabled()) { logger.trace(this.messageCache.size() + " message(s) to flush in session " + getId()); } if (isActive() && this.readyToSend) { if (logger.isTraceEnabled()) { logger.trace("Session is active, ready to flush."); } cancelHeartbeat(); flushCache(); } else { if (logger.isTraceEnabled()) { logger.trace("Session is not active, not ready to flush."); } } } }
Example #8
Source File: AbstractHttpSockJsSession.java From java-technology-stack with MIT License | 6 votes |
/** * Handle all requests, except the first one, to receive messages on a SockJS * HTTP transport based session. * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request * after writing any buffered message frames (or the next one). Streaming-based * transports ("xhr_streaming", "eventsource", and "htmlfile") leave the * response open longer for further streaming of message frames but will also * close it eventually after some amount of data has been sent. * @param request the current request * @param response the current response * @param frameFormat the transport-specific SocksJS frame format to use */ public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException { synchronized (this.responseLock) { try { if (isClosed()) { response.getBody().write(SockJsFrame.closeFrameGoAway().getContentBytes()); return; } this.response = response; this.frameFormat = frameFormat; ServerHttpAsyncRequestControl control = request.getAsyncRequestControl(response); this.asyncRequestControl = control; control.start(-1); disableShallowEtagHeaderFilter(request); handleRequestInternal(request, response, false); this.readyToSend = isActive(); } catch (Throwable ex) { tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to handle SockJS receive request", getId(), ex); } } }
Example #9
Source File: AbstractSockJsSession.java From java-technology-stack with MIT License | 6 votes |
/** * For internal use within a TransportHandler and the (TransportHandler-specific) * session class. */ protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureException { if (logger.isTraceEnabled()) { logger.trace("Preparing to write " + frame); } try { writeFrameInternal(frame); } catch (Throwable ex) { logWriteFrameFailure(ex); try { // Force disconnect (so we won't try to send close frame) disconnect(CloseStatus.SERVER_ERROR); } catch (Throwable disconnectFailure) { // Ignore } try { close(CloseStatus.SERVER_ERROR); } catch (Throwable closeFailure) { // Nothing of consequence, already forced disconnect } throw new SockJsTransportFailureException("Failed to write " + frame, getId(), ex); } }
Example #10
Source File: AbstractHttpSockJsSession.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Handle all requests, except the first one, to receive messages on a SockJS * HTTP transport based session. * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request * after writing any buffered message frames (or the next one). Streaming-based * transports ("xhr_streaming", "eventsource", and "htmlfile") leave the * response open longer for further streaming of message frames but will also * close it eventually after some amount of data has been sent. * @param request the current request * @param response the current response * @param frameFormat the transport-specific SocksJS frame format to use */ public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException { synchronized (this.responseLock) { try { if (isClosed()) { response.getBody().write(SockJsFrame.closeFrameGoAway().getContentBytes()); return; } this.response = response; this.frameFormat = frameFormat; this.asyncRequestControl = request.getAsyncRequestControl(response); this.asyncRequestControl.start(-1); disableShallowEtagHeaderFilter(request); handleRequestInternal(request, response, false); this.readyToSend = isActive(); } catch (Throwable ex) { tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to handle SockJS receive request", getId(), ex); } } }
Example #11
Source File: JettyXhrTransport.java From java-technology-stack with MIT License | 6 votes |
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, @Nullable String body) { Request httpRequest = this.httpClient.newRequest(url).method(method); addHttpHeaders(httpRequest, headers); if (body != null) { httpRequest.content(new StringContentProvider(body)); } ContentResponse response; try { response = httpRequest.send(); } catch (Exception ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } HttpStatus status = HttpStatus.valueOf(response.getStatus()); HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders()); return (response.getContent() != null ? new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) : new ResponseEntity<>(responseHeaders, status)); }
Example #12
Source File: AbstractHttpSockJsSession.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected final void sendMessageInternal(String message) throws SockJsTransportFailureException { synchronized (this.responseLock) { this.messageCache.add(message); if (logger.isTraceEnabled()) { logger.trace(this.messageCache.size() + " message(s) to flush in session " + this.getId()); } if (isActive() && this.readyToSend) { if (logger.isTraceEnabled()) { logger.trace("Session is active, ready to flush."); } cancelHeartbeat(); flushCache(); } else { if (logger.isTraceEnabled()) { logger.trace("Session is not active, not ready to flush."); } } } }
Example #13
Source File: WebSocketServerSockJsSession.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void sendMessageInternal(String message) throws SockJsTransportFailureException { // Open frame not sent yet? // If in the session initialization thread, then cache, otherwise wait. if (!this.openFrameSent) { synchronized (this.initSessionLock) { if (!this.openFrameSent) { this.initSessionCache.add(message); return; } } } cancelHeartbeat(); writeFrame(SockJsFrame.messageFrame(getMessageCodec(), message)); scheduleHeartbeat(); }
Example #14
Source File: StreamingSockJsSession.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected void flushCache() throws SockJsTransportFailureException { while (!getMessageCache().isEmpty()) { String message = getMessageCache().poll(); SockJsMessageCodec messageCodec = getSockJsServiceConfig().getMessageCodec(); SockJsFrame frame = SockJsFrame.messageFrame(messageCodec, message); writeFrame(frame); this.byteCount += (frame.getContentBytes().length + 1); if (logger.isTraceEnabled()) { logger.trace(this.byteCount + " bytes written so far, " + getMessageCache().size() + " more messages not flushed"); } if (this.byteCount >= getSockJsServiceConfig().getStreamBytesLimit()) { logger.trace("Streamed bytes limit reached, recycling current request"); resetRequest(); this.byteCount = 0; break; } } scheduleHeartbeat(); }
Example #15
Source File: HtmlFileTransportHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, AbstractHttpSockJsSession sockJsSession) throws SockJsException { String callback = getCallbackParam(request); if (!StringUtils.hasText(callback)) { response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); try { response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET)); } catch (IOException ex) { sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex); } return; } super.handleRequestInternal(request, response, sockJsSession); }
Example #16
Source File: HtmlFileTransportHandler.java From spring-analysis-note with MIT License | 6 votes |
@Override public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, AbstractHttpSockJsSession sockJsSession) throws SockJsException { String callback = getCallbackParam(request); if (!StringUtils.hasText(callback)) { response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); try { response.getBody().write("\"callback\" parameter required".getBytes(StandardCharsets.UTF_8)); } catch (IOException ex) { sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex); } return; } super.handleRequestInternal(request, response, sockJsSession); }
Example #17
Source File: StreamingSockJsSession.java From spring-analysis-note with MIT License | 6 votes |
@Override protected void flushCache() throws SockJsTransportFailureException { while (!getMessageCache().isEmpty()) { String message = getMessageCache().poll(); SockJsMessageCodec messageCodec = getSockJsServiceConfig().getMessageCodec(); SockJsFrame frame = SockJsFrame.messageFrame(messageCodec, message); writeFrame(frame); this.byteCount += (frame.getContentBytes().length + 1); if (logger.isTraceEnabled()) { logger.trace(this.byteCount + " bytes written so far, " + getMessageCache().size() + " more messages not flushed"); } if (this.byteCount >= getSockJsServiceConfig().getStreamBytesLimit()) { logger.trace("Streamed bytes limit reached, recycling current request"); resetRequest(); this.byteCount = 0; break; } } scheduleHeartbeat(); }
Example #18
Source File: WebSocketServerSockJsSession.java From spring-analysis-note with MIT License | 6 votes |
@Override public void sendMessageInternal(String message) throws SockJsTransportFailureException { // Open frame not sent yet? // If in the session initialization thread, then cache, otherwise wait. if (!this.openFrameSent) { synchronized (this.initSessionLock) { if (!this.openFrameSent) { this.initSessionCache.add(message); return; } } } cancelHeartbeat(); writeFrame(SockJsFrame.messageFrame(getMessageCodec(), message)); scheduleHeartbeat(); }
Example #19
Source File: AbstractHttpSockJsSession.java From spring-analysis-note with MIT License | 6 votes |
@Override protected final void sendMessageInternal(String message) throws SockJsTransportFailureException { synchronized (this.responseLock) { this.messageCache.add(message); if (logger.isTraceEnabled()) { logger.trace(this.messageCache.size() + " message(s) to flush in session " + getId()); } if (isActive() && this.readyToSend) { if (logger.isTraceEnabled()) { logger.trace("Session is active, ready to flush."); } cancelHeartbeat(); flushCache(); } else { if (logger.isTraceEnabled()) { logger.trace("Session is not active, not ready to flush."); } } } }
Example #20
Source File: AbstractHttpSockJsSession.java From spring-analysis-note with MIT License | 6 votes |
/** * Handle all requests, except the first one, to receive messages on a SockJS * HTTP transport based session. * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request * after writing any buffered message frames (or the next one). Streaming-based * transports ("xhr_streaming", "eventsource", and "htmlfile") leave the * response open longer for further streaming of message frames but will also * close it eventually after some amount of data has been sent. * @param request the current request * @param response the current response * @param frameFormat the transport-specific SocksJS frame format to use */ public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException { synchronized (this.responseLock) { try { if (isClosed()) { response.getBody().write(SockJsFrame.closeFrameGoAway().getContentBytes()); return; } this.response = response; this.frameFormat = frameFormat; ServerHttpAsyncRequestControl control = request.getAsyncRequestControl(response); this.asyncRequestControl = control; control.start(-1); disableShallowEtagHeaderFilter(request); handleRequestInternal(request, response, false); this.readyToSend = isActive(); } catch (Throwable ex) { tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to handle SockJS receive request", getId(), ex); } } }
Example #21
Source File: JsonpPollingTransportHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, AbstractHttpSockJsSession sockJsSession) throws SockJsException { try { String callback = getCallbackParam(request); if (!StringUtils.hasText(callback)) { response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET)); return; } } catch (Throwable ex) { sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to send error", sockJsSession.getId(), ex); } super.handleRequestInternal(request, response, sockJsSession); }
Example #22
Source File: AbstractSockJsSession.java From spring-analysis-note with MIT License | 6 votes |
/** * For internal use within a TransportHandler and the (TransportHandler-specific) * session class. */ protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureException { if (logger.isTraceEnabled()) { logger.trace("Preparing to write " + frame); } try { writeFrameInternal(frame); } catch (Throwable ex) { logWriteFrameFailure(ex); try { // Force disconnect (so we won't try to send close frame) disconnect(CloseStatus.SERVER_ERROR); } catch (Throwable disconnectFailure) { // Ignore } try { close(CloseStatus.SERVER_ERROR); } catch (Throwable closeFailure) { // Nothing of consequence, already forced disconnect } throw new SockJsTransportFailureException("Failed to write " + frame, getId(), ex); } }
Example #23
Source File: WebSocketTransportHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); } }
Example #24
Source File: AbstractHttpSockJsSession.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Handle the first request for receiving messages on a SockJS HTTP transport * based session. * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request * after writing the open frame. Streaming-based transports ("xhr_streaming", * "eventsource", and "htmlfile") leave the response open longer for further * streaming of message frames but will also close it eventually after some * amount of data has been sent. * @param request the current request * @param response the current response * @param frameFormat the transport-specific SocksJS frame format to use */ public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException { this.uri = request.getURI(); this.handshakeHeaders = request.getHeaders(); this.principal = request.getPrincipal(); this.localAddress = request.getLocalAddress(); this.remoteAddress = request.getRemoteAddress(); synchronized (this.responseLock) { try { this.response = response; this.frameFormat = frameFormat; this.asyncRequestControl = request.getAsyncRequestControl(response); this.asyncRequestControl.start(-1); disableShallowEtagHeaderFilter(request); // Let "our" handler know before sending the open frame to the remote handler delegateConnectionEstablished(); handleRequestInternal(request, response, true); // Request might have been reset (e.g. polling sessions do after writing) this.readyToSend = isActive(); } catch (Throwable ex) { tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to open session", getId(), ex); } } }
Example #25
Source File: PollingSockJsSession.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void flushCache() throws SockJsTransportFailureException { String[] messages = new String[getMessageCache().size()]; for (int i = 0; i < messages.length; i++) { messages[i] = getMessageCache().poll(); } SockJsMessageCodec messageCodec = getSockJsServiceConfig().getMessageCodec(); SockJsFrame frame = SockJsFrame.messageFrame(messageCodec, messages); writeFrame(frame); resetRequest(); }
Example #26
Source File: SockJsSessionTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void writeFrameIoException() throws Exception { this.session.setExceptionOnWrite(new IOException()); this.session.delegateConnectionEstablished(); try { this.session.writeFrame(SockJsFrame.openFrame()); fail("expected exception"); } catch (SockJsTransportFailureException ex) { assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus()); verify(this.webSocketHandler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR); } }
Example #27
Source File: UndertowXhrTransport.java From spring-analysis-note with MIT License | 5 votes |
private void executeReceiveRequest(final TransportRequest transportRequest, final URI url, final HttpHeaders headers, final XhrClientSockJsSession session, final SettableListenableFuture<WebSocketSession> connectFuture) { if (logger.isTraceEnabled()) { logger.trace("Starting XHR receive request for " + url); } ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() { @Override public void completed(ClientConnection connection) { ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath()); HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST); request.getRequestHeaders().add(headerName, url.getHost()); addHttpHeaders(request, headers); HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders(); connection.sendRequest(request, createReceiveCallback(transportRequest, url, httpHeaders, session, connectFuture)); } @Override public void failed(IOException ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } }; this.httpClient.connect(clientCallback, url, this.worker, this.bufferPool, this.optionMap); }
Example #28
Source File: HttpSendingTransportHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void testJsonpTransport(String callbackValue, boolean expectSuccess) throws Exception { JsonpPollingTransportHandler transportHandler = new JsonpPollingTransportHandler(); transportHandler.initialize(this.sockJsConfig); PollingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler, null); resetRequestAndResponse(); setRequest("POST", "/"); if (callbackValue != null) { this.servletRequest.setQueryString("c=" + callbackValue); this.servletRequest.addParameter("c", callbackValue); } try { transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session); } catch (SockJsTransportFailureException ex) { if (expectSuccess) { throw new AssertionError("Unexpected transport failure", ex); } } if (expectSuccess) { assertEquals(200, this.servletResponse.getStatus()); assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString()); verify(this.webSocketHandler).afterConnectionEstablished(session); } else { assertEquals(500, this.servletResponse.getStatus()); verifyNoMoreInteractions(this.webSocketHandler); } }
Example #29
Source File: UndertowXhrTransport.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void executeReceiveRequest(final TransportRequest transportRequest, final URI url, final HttpHeaders headers, final XhrClientSockJsSession session, final SettableListenableFuture<WebSocketSession> connectFuture) { if (logger.isTraceEnabled()) { logger.trace("Starting XHR receive request for " + url); } ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() { @Override public void completed(ClientConnection connection) { ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath()); HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST); request.getRequestHeaders().add(headerName, url.getHost()); addHttpHeaders(request, headers); HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders(); connection.sendRequest(request, createReceiveCallback(transportRequest, url, httpHeaders, session, connectFuture)); } @Override public void failed(IOException ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } }; this.undertowBufferSupport.httpClientConnect(this.httpClient, clientCallback, url, worker, this.optionMap); }
Example #30
Source File: SockJsSessionTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void writeFrameIoException() throws Exception { this.session.setExceptionOnWrite(new IOException()); this.session.delegateConnectionEstablished(); try { this.session.writeFrame(SockJsFrame.openFrame()); fail("expected exception"); } catch (SockJsTransportFailureException ex) { assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus()); verify(this.webSocketHandler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR); } }