use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project netty-socketio by mrniko.
the class WebSocketTransport method handshake.
private void handshake(ChannelHandlerContext ctx, final UUID sessionId, String path, FullHttpRequest req) {
final Channel channel = ctx.channel();
WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, true, configuration.getMaxFramePayloadLength());
WebSocketServerHandshaker handshaker = factory.newHandshaker(req);
if (handshaker != null) {
ChannelFuture f = handshaker.handshake(channel, req);
f.addListener(new ChannelFutureListener() {
@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);
}
});
} else {
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
}
}
use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project async-http-client by AsyncHttpClient.
the class ChannelManager method upgradePipelineForWebSockets.
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) {
pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true));
pipeline.addBefore(AHC_WS_HANDLER, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, config.getWebSocketMaxFrameSize()));
pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize()));
pipeline.remove(HTTP_CLIENT_CODEC);
}
use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project intellij-community by JetBrains.
the class WebSocketHandshakeHandler method handleWebSocketRequest.
private void handleWebSocketRequest(@NotNull final ChannelHandlerContext context, @NotNull FullHttpRequest request, @NotNull final QueryStringDecoder uriDecoder) {
WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory("ws://" + request.headers().getAsString(HttpHeaderNames.HOST) + uriDecoder.path(), null, false, NettyUtil.MAX_CONTENT_LENGTH);
WebSocketServerHandshaker handshaker = factory.newHandshaker(request);
if (handshaker == null) {
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(context.channel());
return;
}
if (!context.channel().isOpen()) {
return;
}
final Client client = new WebSocketClient(context.channel(), handshaker);
context.channel().attr(ClientManagerKt.getCLIENT()).set(client);
handshaker.handshake(context.channel(), request).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
ClientManager clientManager = WebSocketHandshakeHandler.this.clientManager.getValue();
clientManager.addClient(client);
MessageChannelHandler messageChannelHandler = new MessageChannelHandler(clientManager, getMessageServer());
BuiltInServer.replaceDefaultHandler(context, messageChannelHandler);
ChannelHandlerContext messageChannelHandlerContext = context.pipeline().context(messageChannelHandler);
context.pipeline().addBefore(messageChannelHandlerContext.name(), "webSocketFrameAggregator", new WebSocketFrameAggregator(NettyUtil.MAX_CONTENT_LENGTH));
messageChannelHandlerContext.channel().attr(ClientManagerKt.getCLIENT()).set(client);
connected(client, uriDecoder.parameters());
}
}
});
}
use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project spring-framework by spring-projects.
the class RxNettyWebSocketSession method aggregateFrames.
/**
* Insert 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) {
return this;
}
ChannelHandlerContext frameDecoder = pipeline.context(frameDecoderName);
if (frameDecoder == null) {
throw new IllegalArgumentException("WebSocketFrameDecoder not found: " + frameDecoderName);
}
ChannelHandler frameAggregator = new WebSocketFrameAggregator(DEFAULT_FRAME_MAX_SIZE);
pipeline.addAfter(frameDecoder.name(), FRAME_AGGREGATOR_NAME, frameAggregator);
return this;
}
Aggregations