@Override public void accept(Void aVoid, Throwable throwable) { if (log.isDebugEnabled()) { log.debug(format(channel(), "Handler terminated. Closing Websocket")); } if (throwable == null) { if (channel().isActive()) { sendCloseNow(null); } } else { onOutboundError(throwable); } }
@Override protected void onInboundClose() { onHandlerTerminate(); }
@Override public void onComplete() { if (ops.channel() .isActive()) { ops.sendCloseNow(null); } }
if (msg instanceof FullHttpResponse) { started = true; channel().pipeline() .remove(HttpObjectAggregator.class); FullHttpResponse response = (FullHttpResponse) msg; setNettyResponse(response); if (checkResponseCode(response)) { handshaker.finishHandshake(channel(), response); onInboundError(wshe); return; parentContext().fireContextActive(this); handshakerResult.trySuccess(); channel().writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) msg).content())); ctx.read(); return; ((CloseWebSocketFrame)msg).isFinalFragment()) { if (log.isDebugEnabled()) { log.debug(format(channel(), "CloseWebSocketFrame detected. Closing Websocket")); onInboundComplete(); CloseWebSocketFrame close = (CloseWebSocketFrame) msg; sendCloseNow(new CloseWebSocketFrame(true,
Mono<Void> sendClose(CloseWebSocketFrame frame) { if (CLOSE_SENT.get(this) == 0) { context().onClose(() -> ReactorNetty.safeRelease(frame)); return FutureMono.deferFuture(() -> { if (CLOSE_SENT.getAndSet(this, 1) == 0) { discard(); channel().pipeline().remove(NettyPipeline.ReactiveBridge); return channel().writeAndFlush(frame) .addListener(ChannelFutureListener.CLOSE); } frame.release(); return channel().newSucceededFuture(); }); } frame.release(); return Mono.empty(); }
super(replaced.channel(), replaced); Channel channel = channel(); markPersistent(false); channel.read(); });
@Override public void onError(Throwable t) { ops.onOutboundError(t); }
void sendCloseNow(CloseWebSocketFrame frame) { if (frame != null && !frame.isFinalFragment()) { channel().writeAndFlush(frame); return; } if (CLOSE_SENT.getAndSet(this, 1) == 0) { channel().writeAndFlush(frame == null ? new CloseWebSocketFrame() : frame) .addListener(ChannelFutureListener.CLOSE); } else if (frame != null) { frame.release(); } }
final Mono<Void> withWebsocketSupport(URI url, String protocols, BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> websocketHandler) { //prevent further header to be sent for handshaking if (markSentHeaders()) { addHandlerFirst(NettyPipeline.HttpAggregator, new HttpObjectAggregator(8192)); HttpClientWSOperations ops = new HttpClientWSOperations(url, protocols, this); if (replace(ops)) { Mono<Void> handshake = FutureMono.from(ops.handshakerResult); return applyWebsocketHandler(ops, handshake, websocketHandler); } } else if (isWebsocket()) { HttpClientWSOperations ops = (HttpClientWSOperations) get(channel()); if(ops != null) { Mono<Void> handshake = FutureMono.from(ops.handshakerResult); return applyWebsocketHandler(ops, handshake, websocketHandler); } } else { log.error(format(channel(), "Cannot enable websocket if headers have already been sent")); } return Mono.error(new IllegalStateException("Failed to upgrade to websocket")); }
@Override protected void onOutboundError(Throwable err) { if (channel().isActive()) { sendCloseNow(new CloseWebSocketFrame(1002, "Client internal error")); } }
@Override protected void onInboundCancel() { if (log.isDebugEnabled()) { log.debug(format(channel(), "Cancelling Websocket inbound. Closing Websocket")); } sendCloseNow(null); }