@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { log.error("Can't handshake " + sessionId, future.cause()); return; } channel.pipeline().addBefore(SocketIOChannelInitializer.WEB_SOCKET_TRANSPORT, SocketIOChannelInitializer.WEB_SOCKET_AGGREGATOR, new WebSocketFrameAggregator(configuration.getMaxFramePayloadLength())); connectClient(channel, sessionId); } });
private void switchToWebsocket( ChannelHandlerContext ctx ) { ChannelPipeline p = ctx.pipeline(); p.addLast( new HttpServerCodec(), new HttpObjectAggregator( MAX_WEBSOCKET_HANDSHAKE_SIZE ), new WebSocketServerProtocolHandler( "/", null, false, MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameAggregator( MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameTranslator(), newHandshaker() ); p.remove( this ); }
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.addAfter(WS_ENCODER_HANDLER, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, config.isEnableWebSocketCompression(), config.getWebSocketMaxFrameSize())); if (config.isAggregateWebSocketFrameFragments()) { pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize())); } pipeline.remove(HTTP_CLIENT_CODEC); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { log.error("Can't handshake " + sessionId, future.cause()); return; } channel.pipeline().addBefore(SocketIOChannelInitializer.WEB_SOCKET_TRANSPORT, SocketIOChannelInitializer.WEB_SOCKET_AGGREGATOR, new WebSocketFrameAggregator(configuration.getMaxFramePayloadLength())); connectClient(channel, sessionId); } });
@Override public void operationComplete(ChannelFuture future) throws Exception { final String sessionId = PipelineUtils.getSessionId(requestPath); if (future.isSuccess()) { ctx.channel().pipeline().addBefore( SocketIOChannelInitializer.SOCKETIO_WEBSOCKET_HANDLER, SocketIOChannelInitializer.WEBSOCKET_FRAME_AGGREGATOR, new WebSocketFrameAggregator(maxWebSocketFrameSize)); connect(ctx, req, sessionId); } else { log.error("Can't handshake: {}", sessionId, future.cause()); } } });
/** * Turn this {@link WebsocketInbound} into aggregating mode which will only produce * fully formed frame that have been received fragmented. * * @param maxContentLength the maximum frame length * * @return this inbound */ default WebsocketInbound aggregateFrames(int maxContentLength) { withConnection(c -> c.addHandlerLast(new WebSocketFrameAggregator(maxContentLength))); return this; }
/** * Turn this {@link WebsocketInbound} into aggregating mode which will only produce * fully formed frame that have been received fragmented. * * @param maxContentLength the maximum frame length * * @return this inbound */ default WebsocketInbound aggregateFrames(int maxContentLength) { context().addHandlerLast(new WebSocketFrameAggregator(maxContentLength)); return this; }
/** * Turn this {@link WebsocketInbound} into aggregating mode which will only produce * fully formed frame that have been received fragmented. * * @param maxContentLength the maximum frame length * * @return this inbound */ default WebsocketInbound aggregateFrames(int maxContentLength) { withConnection(c -> c.addHandlerLast(new WebSocketFrameAggregator(maxContentLength))); return this; }
private void switchToWebsocket( ChannelHandlerContext ctx ) { ChannelPipeline p = ctx.pipeline(); p.addLast( new HttpServerCodec(), new HttpObjectAggregator( MAX_WEBSOCKET_HANDSHAKE_SIZE ), new WebSocketServerProtocolHandler( "/", null, false, MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameAggregator( MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameTranslator(), newHandshaker() ); p.remove( this ); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception{ if(evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE){ NettyWebSocket webSocket = new NettyWebSocket(null, handshaker.actualSubprotocol()); ctx.pipeline().addLast("ws-aggregator", new WebSocketFrameAggregator(16 * 1024 * 1024)); // 16MB ctx.pipeline().addLast("websocket", webSocket); ctx.pipeline().remove(this); webSocket.channelActive(ctx); connectListener.onConnect(webSocket); }else ctx.fireUserEventTriggered(evt); } }
/** * Inserts an {@link WebSocketFrameAggregator} after the * {@code WebSocketFrameDecoder} for receiving full messages. * @param channel the channel for the session * @param frameDecoderName the name of the WebSocketFrame decoder */ public RxNettyWebSocketSession aggregateFrames(Channel channel, String frameDecoderName) { ChannelPipeline pipeline = channel.pipeline(); if (pipeline.context(FRAME_AGGREGATOR_NAME) != null) { logger.trace("WebSocketFrameAggregator already registered."); return this; } ChannelHandlerContext frameDecoder = pipeline.context(frameDecoderName); Assert.notNull(frameDecoder, "WebSocketFrameDecoder not found: " + frameDecoderName); ChannelHandler frameAggregator = new WebSocketFrameAggregator(DEFAULT_FRAME_MAX_SIZE); pipeline.addAfter(frameDecoder.name(), FRAME_AGGREGATOR_NAME, frameAggregator); return this; }
if(subProtocol.equals(handshaker.selectedSubprotocol())){ NettyWebSocket webSocket = new NettyWebSocket(handshaker, subProtocol); ctx.pipeline().addLast("ws-aggregator", new WebSocketFrameAggregator(16 * 1024 * 1024)); ctx.pipeline().addLast("websocket", webSocket); ctx.pipeline().remove(this);
@Override protected void channelRead0(ChannelHandlerContext context, Object message) throws Exception { final Channel channel = context.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(channel, (FullHttpResponse) message); channel.pipeline().addBefore(HANDLER_NAME, "websocket-frame-aggregator", new WebSocketFrameAggregator(64 * 1024)); subscriber.onStart(); return; } if (message instanceof FullHttpResponse) { final FullHttpResponse response = (FullHttpResponse) message; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } final WebSocketFrame frame = (WebSocketFrame) message; if (frame instanceof PingWebSocketFrame) { context.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame)frame).retain().content())); } else if (frame instanceof BinaryWebSocketFrame) { final ByteBufInputStream input = new ByteBufInputStream(((BinaryWebSocketFrame)message).content()); final Envelope envelope = Envelope.ADAPTER.decode(input); subscriber.onNext(envelope); } }
private void updatePipeline(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class); p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ServerWriteMetricsHandler(eventsSubject)); ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class); p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ServerReadMetricsHandler(eventsSubject)); if (messageAggregator) { p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength)); } p.remove(this); }
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_HANDLER, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.remove(HTTP_HANDLER); pipeline.addBefore(WS_PROCESSOR, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, config.getWebSocketMaxFrameSize())); pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize())); }
private void updatePipeline(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class); p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ServerWriteMetricsHandler(eventsSubject)); ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class); p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ServerReadMetricsHandler(eventsSubject)); if (messageAggregator) { p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength)); } p.remove(this); }
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_HANDLER, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.remove(HTTP_HANDLER); pipeline.addBefore(WS_PROCESSOR, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, config.getWebSocketMaxFrameSize())); pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize())); }
protocolHandlerCtx.pipeline().addLast(new WebSocketFrameAggregator(WampHandlerConfiguration.MAX_WEBSOCKET_FRAME_SIZE));
private void finishHandshake(ChannelHandlerContext ctx, FullHttpResponse msg, Channel ch) { try { handshaker.finishHandshake(ch, msg); } catch (WebSocketHandshakeException e) { eventsSubject.onEvent(WebSocketClientMetricsEvent.HANDSHAKE_FAILURE, Clock.onEndMillis(handshakeStartTime)); handshakeFuture.setFailure(e); ctx.close(); return; } eventsSubject.onEvent(WebSocketClientMetricsEvent.HANDSHAKE_SUCCESS, Clock.onEndMillis(handshakeStartTime)); ChannelPipeline p = ctx.pipeline(); ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class); p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ClientReadMetricsHandler(eventsSubject)); ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class); p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ClientWriteMetricsHandler(eventsSubject)); if (messageAggregation) { p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength)); } p.remove(HttpObjectAggregator.class); p.remove(this); handshakeFuture.setSuccess(); }
private void finishHandshake(ChannelHandlerContext ctx, FullHttpResponse msg, Channel ch) { try { handshaker.finishHandshake(ch, msg); } catch (WebSocketHandshakeException e) { eventsSubject.onEvent(WebSocketClientMetricsEvent.HANDSHAKE_FAILURE, Clock.onEndMillis(handshakeStartTime)); handshakeFuture.setFailure(e); ctx.close(); return; } eventsSubject.onEvent(WebSocketClientMetricsEvent.HANDSHAKE_SUCCESS, Clock.onEndMillis(handshakeStartTime)); ChannelPipeline p = ctx.pipeline(); ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class); p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ClientReadMetricsHandler(eventsSubject)); ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class); p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ClientWriteMetricsHandler(eventsSubject)); if (messageAggregation) { p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength)); } HttpObjectAggregator aggregator = p.get(HttpObjectAggregator.class); if (aggregator != null) { p.remove(aggregator); } handshakeFuture.setSuccess(); }