void (@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); //NON-NLS 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) { if (future.isSuccess()) { ClientManager clientManager = WebSocketHandshakeHandler.this.clientManager.getValue(); clientManager.addClient(client); MessageChannelHandler messageChannelHandler = new MessageChannelHandler(clientManager, getMessageServer()); BuiltInServer.Companion.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()); } } }); }