@Override protected void doClose() { WebSockets.sendClose(CloseMessage.GOING_AWAY, null, WebSocketChannel.this, null); } };
/** * Sends a complete close message, invoking the callback when complete * * @param closeMessage The close message * @param wsChannel The web socket channel * @param callback The callback to invoke on completion */ public static void sendClose(final CloseMessage closeMessage, final WebSocketChannel wsChannel, final WebSocketCallback<Void> callback) { sendClose(closeMessage, wsChannel, callback, null); }
@Override public void close(final int status, final String reason) { WebSockets.sendClose(status, reason, channel, new WebSocketCallback<Void>() { @Override public void onError(final WebSocketChannel channel, final Void context, final Throwable throwable) { log.error("closing web socket resulted in exception: " + status, throwable); IoUtils.safeClose(channel); } @Override public void complete(final WebSocketChannel channel, final Void context) { IoUtils.safeClose(channel); } }); }
/** * Sends a complete close message, invoking the callback when complete * * @param data The data to send * @param wsChannel The web socket channel * @param callback The callback to invoke on completion */ public static void sendClose(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback<Void> callback) { CloseMessage sm = new CloseMessage(data); sendClose(sm, wsChannel, callback); }
/** * Sends a complete close message, invoking the callback when complete * * @param data The data to send * @param wsChannel The web socket channel * @param callback The callback to invoke on completion */ public static void sendClose(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback<Void> callback) { CloseMessage sm = new CloseMessage(data); sendClose(sm, wsChannel, callback); }
/** * Sends a complete close message, invoking the callback when complete * * @param data The data to send * @param wsChannel The web socket channel * @param callback The callback to invoke on completion * @param context The context object that will be passed to the callback on completion */ public static <T> void sendClose(final ByteBuffer[] data, final WebSocketChannel wsChannel, final WebSocketCallback<T> callback, T context) { CloseMessage sm = new CloseMessage(data); sendClose(sm, wsChannel, callback, context); }
/** * Sends a complete close message, invoking the callback when complete * * @param data The data to send * @param wsChannel The web socket channel * @param callback The callback to invoke on completion * @param context The context object that will be passed to the callback on completion */ public static <T> void sendClose(final ByteBuffer data, final WebSocketChannel wsChannel, final WebSocketCallback<T> callback, T context) { CloseMessage sm = new CloseMessage(data); sendClose(sm, wsChannel, callback, context); }
/** * Sends a complete close message, invoking the callback when complete * * @param code The close code * @param wsChannel The web socket channel * @param callback The callback to invoke on completion */ public static void sendClose(final int code, String reason, final WebSocketChannel wsChannel, final WebSocketCallback<Void> callback) { sendClose(new CloseMessage(code, reason), wsChannel, callback); }
/** * Sends a complete close message, invoking the callback when complete * * @param code The close code * @param wsChannel The web socket channel * @param callback The callback to invoke on completion * @param context The context object that will be passed to the callback on completion */ public static <T> void sendClose(final int code, String reason, final WebSocketChannel wsChannel, final WebSocketCallback<T> callback, T context) { sendClose(new CloseMessage(code, reason), wsChannel, callback, context); }
@Override public Mono<Void> close(CloseStatus status) { CloseMessage cm = new CloseMessage(status.getCode(), status.getReason()); if (!getDelegate().isCloseFrameSent()) { WebSockets.sendClose(cm, getDelegate(), null); } return Mono.empty(); }
@Override protected void handleBrokenSourceChannel(Throwable e) { if (e instanceof UnsupportedEncodingException) { getFramePriority().immediateCloseFrame(); WebSockets.sendClose(new CloseMessage(CloseMessage.MSG_CONTAINS_INVALID_DATA, e.getMessage()).toByteBuffer(), this, null); } else if (e instanceof WebSocketInvalidCloseCodeException) { WebSockets.sendClose(new CloseMessage(CloseMessage.WRONG_CODE, e.getMessage()).toByteBuffer(), this, null); } else if (e instanceof WebSocketFrameCorruptedException) { getFramePriority().immediateCloseFrame(); WebSockets.sendClose(new CloseMessage(CloseMessage.WRONG_CODE, e.getMessage()).toByteBuffer(), this, null); } }
private void checkMaxSize(StreamSourceFrameChannel channel, int res) throws IOException { if(res > 0) { currentSize += res; } if (maxMessageSize > 0 && currentSize > maxMessageSize) { WebSockets.sendClose(new CloseMessage(CloseMessage.MSG_TOO_BIG, WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)), channel.getWebSocketChannel(), null); throw new IOException(WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)); } }
private void checkMaxSize(StreamSourceFrameChannel channel, int res) throws IOException { currentSize += res; if (maxMessageSize > 0 && currentSize > maxMessageSize) { getData().free(); WebSockets.sendClose(new CloseMessage(CloseMessage.MSG_TOO_BIG, WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)), channel.getWebSocketChannel(), null); throw new IOException(WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)); } }
protected void onFullCloseMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { Pooled<ByteBuffer[]> data = message.getData(); try { CloseMessage cm = new CloseMessage(data.getResource()); onCloseMessage(cm, channel); if (!channel.isCloseFrameSent()) { WebSockets.sendClose(cm, channel, null); } } finally { data.close(); } }
@Override protected FrameHeaderData parseFrame(ByteBuffer data) throws IOException { if (partialFrame == null) { partialFrame = receiveFrame(); } try { partialFrame.handle(data); } catch (WebSocketException e) { //the data was corrupt //send a close message WebSockets.sendClose(new CloseMessage(CloseMessage.WRONG_CODE, e.getMessage()).toByteBuffer(), this, null); markReadsBroken(e); if (WebSocketLogger.REQUEST_LOGGER.isDebugEnabled()) { WebSocketLogger.REQUEST_LOGGER.debugf(e, "receive failed due to Exception"); } throw new IOException(e); } if (partialFrame.isDone()) { PartialFrame p = this.partialFrame; this.partialFrame = null; return p; } return null; }
@Override public void close(int code, String reason) { WebSockets.sendClose(code, reason, channel, null); }
/** * Sends a complete close message, invoking the callback when complete * * @param closeMessage The close message * @param wsChannel The web socket channel * @param callback The callback to invoke on completion */ public static void sendClose(final CloseMessage closeMessage, final WebSocketChannel wsChannel, final WebSocketCallback<Void> callback) { sendClose(closeMessage, wsChannel, callback, null); }
private void checkMaxSize(StreamSourceFrameChannel channel, int res) throws IOException { if(res > 0) { currentSize += res; } if (maxMessageSize > 0 && currentSize > maxMessageSize) { WebSockets.sendClose(new CloseMessage(CloseMessage.MSG_TOO_BIG, WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)), channel.getWebSocketChannel(), null); throw new IOException(WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)); } }
private void checkMaxSize(StreamSourceFrameChannel channel, int res) throws IOException { currentSize += res; if (maxMessageSize > 0 && currentSize > maxMessageSize) { getData().free(); WebSockets.sendClose(new CloseMessage(CloseMessage.MSG_TOO_BIG, WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)), channel.getWebSocketChannel(), null); throw new IOException(WebSocketMessages.MESSAGES.messageToBig(maxMessageSize)); } }
protected void onFullCloseMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { Pooled<ByteBuffer[]> data = message.getData(); try { CloseMessage cm = new CloseMessage(data.getResource()); onCloseMessage(cm, channel); if (!channel.isCloseFrameSent()) { WebSockets.sendClose(cm, channel, null); } } finally { data.close(); } }