List of usage examples for io.netty.handler.codec.http.websocketx WebSocketFrameAggregator WebSocketFrameAggregator
public WebSocketFrameAggregator(int maxContentLength)
From source file:c5db.client.C5ConnectionInitializer.java
License:Apache License
@Override protected void initChannel(SocketChannel ch) throws Exception { decoder = new WebsocketProtostuffDecoder(handShaker); final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("http-client", new HttpClientCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(C5Constants.MAX_RESPONSE_SIZE)); pipeline.addLast("websec-codec", new WebsocketProtostuffEncoder(handShaker)); pipeline.addLast("websocket-aggregator", new WebSocketFrameAggregator(C5Constants.MAX_RESPONSE_SIZE)); pipeline.addLast("message-codec", decoder); pipeline.addLast("message-handler", new FutureBasedMessageHandler()); }
From source file:c5db.regionserver.RegionServerService.java
License:Apache License
@Override protected void doStart() { fiber.start();//from ww w . j a v a 2 s. c om fiber.execute(() -> { // we need the tablet module: ListenableFuture<C5Module> f = server.getModule(ModuleType.Tablet); Futures.addCallback(f, new FutureCallback<C5Module>() { @Override public void onSuccess(final C5Module result) { tabletModule = (TabletModule) result; bootstrap.group(acceptGroup, workerGroup).option(ChannelOption.SO_REUSEADDR, true) .childOption(ChannelOption.TCP_NODELAY, true).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("http-server-codec", new HttpServerCodec()); p.addLast("http-agg", new HttpObjectAggregator(C5ServerConstants.MAX_CALL_SIZE)); p.addLast("websocket-agg", new WebSocketFrameAggregator(C5ServerConstants.MAX_CALL_SIZE)); p.addLast("decoder", new WebsocketProtostuffDecoder("/websocket")); p.addLast("encoder", new WebsocketProtostuffEncoder()); p.addLast("handler", new RegionServerHandler(RegionServerService.this)); } }); bootstrap.bind(port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { listenChannel = future.channel(); notifyStarted(); } else { LOG.error("Unable to find Region Server to {} {}", port, future.cause()); notifyFailed(future.cause()); } } }); } @Override public void onFailure(Throwable t) { notifyFailed(t); } }, fiber); }); }
From source file:com.corundumstudio.socketio.transport.WebSocketTransport.java
License:Apache License
private void handshake(ChannelHandlerContext ctx, final UUID sessionId, String path, FullHttpRequest req) { final Channel channel = ctx.channel(); WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, false, configuration.getMaxFramePayloadLength()); WebSocketServerHandshaker handshaker = factory.newHandshaker(req); if (handshaker != null) { ChannelFuture f = handshaker.handshake(channel, req); f.addListener(new ChannelFutureListener() { @Override/* w w w . jav a 2 s. c o m*/ 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()); } }
From source file:game.net.websocket.WebSocketServerInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); }// w ww . j a v a 2 s . c o m pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocket13FrameDecoder(true, true, 65536)); pipeline.addLast(new WebSocket13FrameEncoder(false)); pipeline.addLast(new WebSocketFrameAggregator(65536)); pipeline.addLast(new IdleStateHandler(60, 60, 60)); pipeline.addLast(new WebSocketServerHandler()); }
From source file:io.reactivex.netty.protocol.http.websocket.WebSocketClientHandler.java
License:Apache License
private void finishHandshake(ChannelHandlerContext ctx, FullHttpResponse msg, Channel ch) { try {//w w w . j ava 2s. com 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(); }
From source file:io.reactivex.netty.protocol.http.websocket.WebSocketServerHandler.java
License:Apache License
private void updatePipeline(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline();//from w ww . j av a 2s . c om 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); }
From source file:org.asynchttpclient.netty.channel.ChannelManager.java
License:Open Source License
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);/*from www . jav a 2 s . c o m*/ }
From source file:org.asynchttpclient.providers.netty.channel.ChannelManager.java
License:Open Source License
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_HANDLER, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.remove(HTTP_HANDLER);//from w w w . j a v a 2 s .com pipeline.addBefore(WS_PROCESSOR, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, nettyConfig.getWebSocketMaxFrameSize())); pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(nettyConfig.getWebSocketMaxBufferSize())); }
From source file:org.eclipse.milo.opcua.stack.client.transport.websocket.OpcClientWebSocketChannelInitializer.java
License:Open Source License
@Override protected void initChannel(SocketChannel channel) throws Exception { String endpointUrl = config.getEndpoint().getEndpointUrl(); String scheme = EndpointUtil.getScheme(endpointUrl); TransportProfile transportProfile = TransportProfile.fromUri(config.getEndpoint().getTransportProfileUri()); String subprotocol;/* www .j a v a 2 s . co m*/ if (transportProfile == TransportProfile.WSS_UASC_UABINARY) { subprotocol = "opcua+cp"; } else if (transportProfile == TransportProfile.WSS_UAJSON) { subprotocol = "opcua+uajson"; } else { throw new UaException(StatusCodes.Bad_InternalError, "unexpected TransportProfile: " + transportProfile); } if ("opc.wss".equalsIgnoreCase(scheme)) { SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE) .build(); channel.pipeline().addLast(sslContext.newHandler(channel.alloc())); } int maxMessageSize = config.getMessageLimits().getMaxMessageSize(); channel.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); channel.pipeline().addLast(new HttpClientCodec()); channel.pipeline().addLast(new HttpObjectAggregator(maxMessageSize)); channel.pipeline() .addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker( new URI(endpointUrl), WebSocketVersion.V13, subprotocol, true, new DefaultHttpHeaders(), config.getMessageLimits().getMaxChunkSize()))); channel.pipeline().addLast(new WebSocketFrameAggregator(config.getMessageLimits().getMaxMessageSize())); // OpcClientWebSocketFrameCodec adds UascClientAcknowledgeHandler when the WS upgrade is done. channel.pipeline().addLast(new OpcClientWebSocketBinaryFrameCodec(config, handshake)); }
From source file:org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession.java
License:Apache License
/** * 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 */// w ww. jav a 2s.c o m 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; }