private void handleCloseFrame(ChannelHandlerContext ctx, CloseWebSocketFrame cwsf) { if (closed.compareAndSet(false, true)) { CloseReason cr = new CloseReason(cwsf.statusCode(), cwsf.reasonText()); handleCloseReason(ctx, cr); } }
public void handle(final Object msg) { ready(); if (msg instanceof TextWebSocketFrame) { onTextCallback.accept(((TextWebSocketFrame) msg).text()); } else if (msg instanceof BinaryWebSocketFrame) { onBinaryCallback.accept(((BinaryWebSocketFrame) msg).content().nioBuffer()); } else if (msg instanceof CloseWebSocketFrame) { CloseWebSocketFrame closeFrame = ((CloseWebSocketFrame) msg).retain(); int statusCode = closeFrame.statusCode(); onCloseCallback.accept(statusCode == -1 ? WebSocket.NORMAL.code() : statusCode, Optional.ofNullable(closeFrame.reasonText())); handshaker.close(ctx.channel(), closeFrame).addListener(CLOSE); } else if (msg instanceof Throwable) { onErrorCallback.accept((Throwable) msg); } }
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame(frame.statusCode(), frame.reasonText()); chctx.writeAndFlush(closeFrame).addListener(ChannelFutureListener.CLOSE); closeFrameSent = true;
public void handleFrame(WebSocketFrame frame) { if (frame instanceof TextWebSocketFrame) { onTextFrame((TextWebSocketFrame) frame); } else if (frame instanceof BinaryWebSocketFrame) { onBinaryFrame((BinaryWebSocketFrame) frame); } else if (frame instanceof CloseWebSocketFrame) { Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame; onClose(closeFrame.statusCode(), closeFrame.reasonText()); Channels.silentlyCloseChannel(channel); } else if (frame instanceof PingWebSocketFrame) { onPingFrame((PingWebSocketFrame) frame); } else if (frame instanceof PongWebSocketFrame) { onPongFrame((PongWebSocketFrame) frame); } else if (frame instanceof ContinuationWebSocketFrame) { onContinuationFrame((ContinuationWebSocketFrame) frame); } }
assertEquals(msg.getClass(), CloseWebSocketFrame.class); CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete();
assertEquals(msg.getClass(), CloseWebSocketFrame.class); CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete();
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame(frame.statusCode(), frame.reasonText()); chctx.writeAndFlush(closeFrame).addListener(ChannelFutureListener.CLOSE); closeFrameSent = true;
assertEquals(msg.getClass(), CloseWebSocketFrame.class); CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete();
assertEquals(msg.getClass(), CloseWebSocketFrame.class); CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete();
private ChannelFuture initiateConnectionClosure(CloseWebSocketFrame closeWebSocketFrame) { if (closeFrameSent) { throw new IllegalStateException("Close frame already sent. Cannot send close frame again."); } closeFrameSent = true; closeInitiatedStatusCode = closeWebSocketFrame.statusCode(); closeInitiatedStatusCode = closeInitiatedStatusCode == -1 ? 1005 : closeInitiatedStatusCode; ChannelPromise closePromise = ctx.newPromise(); ctx.writeAndFlush(closeWebSocketFrame).addListener(future -> { frameHandler.setClosePromise(closePromise); Throwable cause = future.cause(); if (!future.isSuccess() && cause != null) { ctx.close().addListener(closeFuture -> closePromise.setFailure(cause)); } }); return closePromise; }
public void handle(final Object msg) { ready(); if (msg instanceof TextWebSocketFrame) { onTextCallback.accept(((TextWebSocketFrame) msg).text()); } else if (msg instanceof BinaryWebSocketFrame) { onBinaryCallback.accept(((BinaryWebSocketFrame) msg).content().nioBuffer()); } else if (msg instanceof CloseWebSocketFrame) { CloseWebSocketFrame closeFrame = ((CloseWebSocketFrame) msg).retain(); int statusCode = closeFrame.statusCode(); onCloseCallback.accept(statusCode == -1 ? WebSocket.NORMAL.code() : statusCode, Optional.ofNullable(closeFrame.reasonText())); handshaker.close(ctx.channel(), closeFrame).addListener(CLOSE); } else if (msg instanceof Throwable) { onErrorCallback.accept((Throwable) msg); } }
private void notifyCloseMessage(CloseWebSocketFrame closeWebSocketFrame) throws ServerConnectorException { String reasonText = closeWebSocketFrame.reasonText(); int statusCode = closeWebSocketFrame.statusCode(); ctx.channel().close(); channelSession.setIsOpen(false); WebSocketMessageImpl webSocketCloseMessage = new WebSocketCloseMessageImpl(statusCode, reasonText); webSocketCloseMessage = setupCommonProperties(webSocketCloseMessage); connectorFuture.notifyWSListener((WebSocketCloseMessage) webSocketCloseMessage); }
private void notifyCloseMessage(CloseWebSocketFrame closeWebSocketFrame, ChannelHandlerContext ctx) throws ServerConnectorException { String reasonText = closeWebSocketFrame.reasonText(); int statusCode = closeWebSocketFrame.statusCode(); ctx.channel().close(); if (channelSession == null) { throw new ServerConnectorException("Cannot find initialized channel session"); } channelSession.setIsOpen(false); WebSocketMessageImpl webSocketCloseMessage = new WebSocketCloseMessageImpl(statusCode, reasonText); webSocketCloseMessage = setupCommonProperties(webSocketCloseMessage, ctx); connectorListener.onMessage((WebSocketCloseMessage) webSocketCloseMessage); }
private void notifyCloseMessage(CloseWebSocketFrame closeWebSocketFrame) throws WebSocketConnectorException { String reasonText = closeWebSocketFrame.reasonText(); int statusCode = closeWebSocketFrame.statusCode(); if (statusCode == -1) { statusCode = 1005; } // closePromise == null means that WebSocketConnection has not yet initiated a connection closure. if (closePromise == null) { DefaultWebSocketMessage webSocketCloseMessage = new DefaultWebSocketCloseMessage(statusCode, reasonText); setupCommonProperties(webSocketCloseMessage); connectorFuture.notifyWebSocketListener((WebSocketCloseMessage) webSocketCloseMessage); } else { if (webSocketConnection.getCloseInitiatedStatusCode() != statusCode) { String errMsg = String.format( "Expected status code %d but found %d in echoed close frame from remote endpoint", webSocketConnection.getCloseInitiatedStatusCode(), statusCode); closePromise.setFailure(new IllegalStateException(errMsg)); return; } closePromise.setSuccess(); } closeWebSocketFrame.release(); }
Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText()); } else { ByteBuf buf = frame.content();
Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText()); } else { ByteBuf buf = frame.content();