io.netty.handler.codec.http.HttpObjectAggregator Java Examples
The following examples show how to use
io.netty.handler.codec.http.HttpObjectAggregator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Http2ServerChannelInitializer.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSSL(SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); // 先通过 SSL/TLS 协商版本 p.addLast(sslCtx.newHandler(ch.alloc())); // 根据版本加载不同的 ChannelHandler p.addLast(new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) { @Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { ctx.pipeline().addLast(bizGroup, "Http2ChannelHandler", new Http2ChannelHandlerBuilder(serverHandler).build()); return; } if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) { ctx.pipeline().addLast("HttpServerCodec", new HttpServerCodec()); ctx.pipeline().addLast("HttpObjectAggregator", new HttpObjectAggregator(maxHttpContentLength)); ctx.pipeline().addLast(bizGroup, "Http1ChannelHandler", new Http1ServerChannelHandler(serverHandler)); return; } throw new IllegalStateException("unknown protocol: " + protocol); } }); }
Example #2
Source File: InboundWebsocketChannelInitializer.java From micro-integrator with Apache License 2.0 | 6 votes |
@Override protected void initChannel(SocketChannel websocketChannel) throws Exception { if (sslConfiguration != null) { SslHandler sslHandler = new SSLHandlerFactory(sslConfiguration).create(); websocketChannel.pipeline().addLast("ssl", sslHandler); } ChannelPipeline p = websocketChannel.pipeline(); p.addLast("codec", new HttpServerCodec()); p.addLast("aggregator", new HttpObjectAggregator(65536)); p.addLast("frameAggregator", new WebSocketFrameAggregator(Integer.MAX_VALUE)); InboundWebsocketSourceHandler sourceHandler = new InboundWebsocketSourceHandler(); sourceHandler.setClientBroadcastLevel(clientBroadcastLevel); sourceHandler.setDispatchToCustomSequence(dispatchToCustomSequence); sourceHandler.setPortOffset(portOffset); if (outflowDispatchSequence != null) sourceHandler.setOutflowDispatchSequence(outflowDispatchSequence); if (outflowErrorSequence != null) sourceHandler.setOutflowErrorSequence(outflowErrorSequence); if (subprotocolHandlers != null) sourceHandler.setSubprotocolHandlers(subprotocolHandlers); if (pipelineHandler != null) p.addLast("pipelineHandler", pipelineHandler.getClass().getConstructor().newInstance()); p.addLast("handler", sourceHandler); }
Example #3
Source File: AbstractHttpConnector.java From minnal with Apache License 2.0 | 6 votes |
public void initialize() { logger.info("Initializing the connector"); EventLoopGroup bossGroup = new NioEventLoopGroup(configuration.getIoWorkerThreadCount()); EventLoopGroup workerGroup = new NioEventLoopGroup(configuration.getIoWorkerThreadCount()); bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .childOption(ChannelOption.TCP_NODELAY, true) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new HttpRequestDecoder(), new HttpResponseEncoder(), new HttpObjectAggregator(configuration.getMaxContentLength()), AbstractHttpConnector.this); addChannelHandlers(ch.pipeline()); } }); }
Example #4
Source File: HttpServerInitializer.java From SI with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } pipeline.addLast(new HttpResponseEncoder()); pipeline.addLast(new HttpRequestDecoder()); // Uncomment the following line if you don't want to handle HttpChunks. //pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); //p.addLast(new HttpObjectAggregator(1048576)); // Remove the following line if you don't want automatic content compression. //pipeline.addLast(new HttpContentCompressor()); // Uncomment the following line if you don't want to handle HttpContents. pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast("readTimeoutHandler", new ReadTimeoutHandler(READ_TIMEOUT)); pipeline.addLast("myHandler", new MyHandler()); pipeline.addLast("handler", new HttpServerHandler(listener)); }
Example #5
Source File: Balancer.java From timely with Apache License 2.0 | 6 votes |
protected ChannelHandler setupWSChannel(BalancerConfiguration balancerConfig, SslContext sslCtx, MetricResolver metricResolver, WsClientPool wsClientPool) { return new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc())); ch.pipeline().addLast("httpServer", new HttpServerCodec()); ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536)); ch.pipeline().addLast("sessionExtractor", new WebSocketFullRequestHandler()); ch.pipeline().addLast("idle-handler", new IdleStateHandler(balancerConfig.getWebsocket().getTimeout(), 0, 0)); ch.pipeline().addLast("ws-protocol", new WebSocketServerProtocolHandler(WS_PATH, null, true, 65536, false, true)); ch.pipeline().addLast("wsDecoder", new WebSocketRequestDecoder(balancerConfig.getSecurity())); ch.pipeline().addLast("httpRelay", new WsRelayHandler(balancerConfig, metricResolver, wsClientPool)); ch.pipeline().addLast("error", new WSTimelyExceptionHandler()); } }; }
Example #6
Source File: HttpClientChannelPoolHandler.java From protools with Apache License 2.0 | 6 votes |
@Override public void channelCreated(Channel channel) { NioSocketChannel nioSocketChannel = (NioSocketChannel) channel; nioSocketChannel.config().setTcpNoDelay(true).setKeepAlive(true); final ChannelPipeline p = nioSocketChannel.pipeline(); //HTTPS if (sslCtx != null) { p.addLast(sslCtx.newHandler(channel.alloc())); } p.addLast(new HttpClientCodec(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)); p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE)); }
Example #7
Source File: WebWhoisModule.java From nomulus with Apache License 2.0 | 6 votes |
/** * {@link Provides} the list of providers of {@link ChannelHandler}s that are used for https * protocol. */ @Provides @HttpsWhoisProtocol static ImmutableList<Provider<? extends ChannelHandler>> providerHttpsWhoisHandlerProviders( @HttpsWhoisProtocol Provider<SslClientInitializer<NioSocketChannel>> sslClientInitializerProvider, Provider<HttpClientCodec> httpClientCodecProvider, Provider<HttpObjectAggregator> httpObjectAggregatorProvider, Provider<WebWhoisMessageHandler> messageHandlerProvider, Provider<WebWhoisActionHandler> webWhoisActionHandlerProvider) { return ImmutableList.of( sslClientInitializerProvider, httpClientCodecProvider, httpObjectAggregatorProvider, messageHandlerProvider, webWhoisActionHandlerProvider); }
Example #8
Source File: NetworkManager.java From Clither-Server with GNU General Public License v3.0 | 6 votes |
@Override protected void initChannel(SocketChannel ch) throws Exception { try { ch.config().setOption(ChannelOption.IP_TOS, 0x18); } catch (ChannelException ex) { // IP_TOS not supported by platform, ignore } ch.config().setAllocator(PooledByteBufAllocator.DEFAULT); ch.pipeline().addLast(new HttpServerCodec()); ch.pipeline().addLast(new HttpObjectAggregator(65536)); ch.pipeline().addLast(new Handshaker()); ch.pipeline().addLast(new WebSocketHandler()); ch.pipeline().addLast(new PacketDecoder()); ch.pipeline().addLast(new PacketEncoder()); ch.pipeline().addLast(new ClientHandler(server)); }
Example #9
Source File: HttpCacheClient.java From bazel with Apache License 2.0 | 6 votes |
@SuppressWarnings("FutureReturnValueIgnored") private void releaseUploadChannel(Channel ch) { if (ch.isOpen()) { try { ch.pipeline().remove(IdleTimeoutHandler.class); ch.pipeline().remove(HttpResponseDecoder.class); ch.pipeline().remove(HttpObjectAggregator.class); ch.pipeline().remove(HttpRequestEncoder.class); ch.pipeline().remove(ChunkedWriteHandler.class); ch.pipeline().remove(HttpUploadHandler.class); } catch (NoSuchElementException e) { // If the channel is in the process of closing but not yet closed, some handlers could have // been removed and would cause NoSuchElement exceptions to be thrown. Because handlers are // removed in reverse-order, if we get a NoSuchElement exception, the following handlers // should have been removed. } } channelPool.release(ch); }
Example #10
Source File: ProtocolHandler.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void switchToHttp(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); p.addLast("http-decoder", new HttpRequestDecoder()); p.addLast("http-aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)); p.addLast("http-encoder", new HttpResponseEncoder()); //create it lazily if and when we need it if (httpKeepAliveRunnable == null) { long httpServerScanPeriod = ConfigurationHelper.getLongProperty(TransportConstants.HTTP_SERVER_SCAN_PERIOD_PROP_NAME, TransportConstants.DEFAULT_HTTP_SERVER_SCAN_PERIOD, nettyAcceptor.getConfiguration()); httpKeepAliveRunnable = new HttpKeepAliveRunnable(); Future<?> future = scheduledThreadPool.scheduleAtFixedRate(httpKeepAliveRunnable, httpServerScanPeriod, httpServerScanPeriod, TimeUnit.MILLISECONDS); httpKeepAliveRunnable.setFuture(future); } long httpResponseTime = ConfigurationHelper.getLongProperty(TransportConstants.HTTP_RESPONSE_TIME_PROP_NAME, TransportConstants.DEFAULT_HTTP_RESPONSE_TIME, nettyAcceptor.getConfiguration()); HttpAcceptorHandler httpHandler = new HttpAcceptorHandler(httpKeepAliveRunnable, httpResponseTime, ctx.channel()); ctx.pipeline().addLast("http-handler", httpHandler); p.addLast(new ProtocolDecoder(false, true)); p.remove(this); }
Example #11
Source File: HttpProxyServer.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override protected void configure(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); switch (testMode) { case INTERMEDIARY: p.addLast(new HttpServerCodec()); p.addLast(new HttpObjectAggregator(1)); p.addLast(new HttpIntermediaryHandler()); break; case TERMINAL: p.addLast(new HttpServerCodec()); p.addLast(new HttpObjectAggregator(1)); p.addLast(new HttpTerminalHandler()); break; case UNRESPONSIVE: p.addLast(UnresponsiveHandler.INSTANCE); break; } }
Example #12
Source File: WebSocketInitializer.java From jeesupport with MIT License | 6 votes |
@Override protected void initChannel( SocketChannel _channel ) throws Exception { ChannelPipeline pipeline = _channel.pipeline(); // 是否使用客户端模式 if( CommonConfig.getBoolean( "jees.jsts.websocket.ssl.enable", false ) ){ SSLEngine engine = sslContext1.createSSLEngine(); // 是否需要验证客户端 engine.setUseClientMode(false); // engine.setNeedClientAuth(false); pipeline.addFirst("ssl", new SslHandler( engine )); } pipeline.addLast( new IdleStateHandler( 100 , 0 , 0 , TimeUnit.SECONDS ) ); pipeline.addLast( new HttpServerCodec() ); pipeline.addLast( new ChunkedWriteHandler() ); pipeline.addLast( new HttpObjectAggregator( 8192 ) ); pipeline.addLast( new WebSocketServerProtocolHandler( CommonConfig.getString( ISocketBase.Netty_WebSocket_Url, "/" ) ) ); pipeline.addLast( CommonContextHolder.getBean( WebSocketHandler.class ) ); }
Example #13
Source File: ComponentTestUtils.java From riposte with Apache License 2.0 | 6 votes |
public static Bootstrap createNettyHttpClientBootstrap() { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new HttpClientCodec()); p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE)); p.addLast("clientResponseHandler", new SimpleChannelInboundHandler<HttpObject>() { @Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { throw new RuntimeException("Client response handler was not setup before the call"); } }); } }); return bootstrap; }
Example #14
Source File: WebsocketServer.java From camunda-bpm-workbench with GNU Affero General Public License v3.0 | 6 votes |
public ChannelFuture run() { final ServerBootstrap httpServerBootstrap = new ServerBootstrap(); httpServerBootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .localAddress(new InetSocketAddress(port)) .childHandler(new ChannelInitializer<SocketChannel>() { public void initChannel(final SocketChannel ch) throws Exception { ch.pipeline().addLast( new HttpResponseEncoder(), new HttpRequestDecoder(), new HttpObjectAggregator(65536), new WebSocketServerProtocolHandler("/debug-session"), new DebugProtocolHandler(debugWebsocketConfiguration)); } }); LOGG.log(Level.INFO, "starting camunda BPM debug HTTP websocket interface on port "+port+"."); return httpServerBootstrap.bind(port); }
Example #15
Source File: NettyHttpServletPipelineFactory.java From cxf with Apache License 2.0 | 6 votes |
protected ChannelPipeline getDefaulHttpChannelPipeline(Channel channel) throws Exception { // Create a default pipeline implementation. ChannelPipeline pipeline = channel.pipeline(); SslHandler sslHandler = configureServerSSLOnDemand(); if (sslHandler != null) { LOG.log(Level.FINE, "Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler); pipeline.addLast("ssl", sslHandler); } pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("aggregator", new HttpObjectAggregator(maxChunkContentSize)); // Remove the following line if you don't want automatic content // compression. pipeline.addLast("deflater", new HttpContentCompressor()); // Set up the idle handler pipeline.addLast("idle", new IdleStateHandler(nettyHttpServerEngine.getReadIdleTime(), nettyHttpServerEngine.getWriteIdleTime(), 0)); return pipeline; }
Example #16
Source File: HttpStaticFileServerInitializer.java From codes-scratch-zookeeper-netty with Apache License 2.0 | 6 votes |
@Override protected void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. CorsConfig corsConfig = CorsConfig.withAnyOrigin().build(); ChannelPipeline pipeline = ch.pipeline(); // Uncomment the following line if you want HTTPS //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine(); //engine.setUseClientMode(false); //pipeline.addLast("ssl", new SslHandler(engine)); pipeline.addLast("encoder", new HttpResponseEncoder()); pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("aggregator", new HttpObjectAggregator(8388608)); // 8MB //pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("cors", new CorsHandler(corsConfig)); pipeline.addLast("handler", new HttpStaticFileServerHandler()); }
Example #17
Source File: Http2OrHttpHandler.java From product-microgateway with Apache License 2.0 | 6 votes |
@Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { ctx.pipeline().addLast(new Http2HandlerBuilder().build()); return; } if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) { ctx.pipeline().addLast(new HttpServerCodec(), new HttpObjectAggregator(MAX_CONTENT_LENGTH), new Http1Handler("ALPN Negotiation")); return; } throw new IllegalStateException("unknown protocol: " + protocol); }
Example #18
Source File: NettyServerUtil.java From netty-cookbook with Apache License 2.0 | 5 votes |
public static void newHttpServerBootstrap(String ip, int port, SimpleChannelInboundHandler<? extends FullHttpRequest> handler){ ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast("decoder", new HttpRequestDecoder()); p.addLast("aggregator", new HttpObjectAggregator(65536)); p.addLast("encoder", new HttpResponseEncoder()); p.addLast("chunkedWriter", new ChunkedWriteHandler()); p.addLast("handler", handler ); } }; newHttpServerBootstrap(ip, port, channelInitializer); }
Example #19
Source File: BitsoWebSocket.java From bitso-java with MIT License | 5 votes |
public void openConnection() throws InterruptedException{ Bootstrap bootstrap = new Bootstrap(); final WebSocketClientHandler handler = new WebSocketClientHandler( WebSocketClientHandshakerFactory.newHandshaker( mUri, WebSocketVersion.V08, null, false, new DefaultHttpHeaders())); bootstrap.group(mGroup) .channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel socketChannel){ ChannelPipeline channelPipeline = socketChannel.pipeline(); channelPipeline.addLast(mSslContext.newHandler( socketChannel.alloc(), mUri.getHost(), PORT)); channelPipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), handler); } }); mChannel = bootstrap.connect(mUri.getHost(), PORT).sync().channel(); handler.handshakeFuture().sync(); setConnected(Boolean.TRUE); }
Example #20
Source File: HttpRequester.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc(), this.uri.getHost(), this.port)); } pipeline.addLast(new IdleStateHandler(IDLE_TIMEOUT_SECONDS, IDLE_TIMEOUT_SECONDS, IDLE_TIMEOUT_SECONDS)); pipeline.addLast(new HttpIdleStateHandler()); pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); pipeline.addLast(new HttpClientHandler()); }
Example #21
Source File: HttpServerInitializer.java From java-tutorial with MIT License | 5 votes |
@Override protected void initChannel(SocketChannel socketChannel) { //channel 代表了一个socket. ChannelPipeline pipeline = socketChannel.pipeline(); pipeline.addLast(new ReadTimeoutHandler(1)); /** * http-request解码器 * http服务器端对request解码 */ pipeline.addLast("decoder", new HttpRequestDecoder(8192, 8192, 8192)); /** * http-response解码器 * http服务器端对response编码 */ pipeline.addLast("encoder", new HttpResponseEncoder()); /** * 把多个消息转换为一个单一的FullHttpRequest或是FullHttpResponse */ pipeline.addLast("aggregator", new HttpObjectAggregator(10 * 1024 * 1024)); /** * 压缩 */ pipeline.addLast(new HttpContentCompressor()); /** * handler分为两种,inbound handler,outbound handler,分别处理 流入,流出。 * 服务端业务逻辑 */ pipeline.addLast(new HttpServerHandler()); }
Example #22
Source File: SimpleWampWebsocketListener.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WampServerWebsocketHandler(uri.getPath().length()==0 ? "/" : uri.getPath(), router, serializations)); pipeline.addLast(new WebSocketServerHandler(uri)); }
Example #23
Source File: DefaultInitializer.java From xian with Apache License 2.0 | 5 votes |
private void initInboundHandlers(ChannelPipeline p) { p.addLast("httpRequestDecoder", new HttpRequestDecoder()); p.addLast("httpAggregator", new HttpObjectAggregator(Config.getClientMaxBodySize())); p.addLast("reqReceived", new ReqReceived()); p.addLast("reqDecoderAux", new RequestDecoderAux()); p.addLast("businessHandler", new BusinessHandler()); p.addLast("reqSubmitted", new ReqSubmitted()); p.addLast("exceptionHandler", new DefaultExceptionHandler()); }
Example #24
Source File: Http2ServerStreamHandler.java From ambry with Apache License 2.0 | 5 votes |
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().addLast(http2StreamFrameToHttpObjectCodec); ctx.pipeline().addLast(new HttpObjectAggregator(http2ClientConfig.http2MaxContentLength)); ctx.pipeline().addLast(ambryNetworkRequestHandler); ctx.pipeline().addLast(ambrySendToHttp2Adaptor); }
Example #25
Source File: WebSocketServerInitializer.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocketServerHandler()); }
Example #26
Source File: HttpStaticFileServerInitializer.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new ChunkedWriteHandler()); pipeline.addLast(new HttpStaticFileServerHandler()); }
Example #27
Source File: HttpCorsServerInitializer.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void initChannel(SocketChannel ch) { CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build(); ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } pipeline.addLast(new HttpResponseEncoder()); pipeline.addLast(new HttpRequestDecoder()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new ChunkedWriteHandler()); pipeline.addLast(new CorsHandler(corsConfig)); pipeline.addLast(new OkResponseHandler()); }
Example #28
Source File: Http2BlockingChannelStreamChannelInitializer.java From ambry with Apache License 2.0 | 5 votes |
@Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(http2StreamFrameToHttpObjectCodec); p.addLast(new HttpObjectAggregator(http2MaxContentLength)); p.addLast(http2BlockingChannelResponseHandler); p.addLast(ambrySendToHttp2Adaptor); }
Example #29
Source File: NettyHttpServerInitializer.java From redant with Apache License 2.0 | 5 votes |
/** * 可以在 HttpServerCodec 之后添加这些 ChannelHandler 进行开启高级特性 */ private void addAdvanced(ChannelPipeline pipeline){ if(CommonConstants.USE_COMPRESS) { // 对 http 响应结果开启 gizp 压缩 pipeline.addLast(new HttpContentCompressor()); } if(CommonConstants.USE_AGGREGATOR) { // 将多个HttpRequest组合成一个FullHttpRequest pipeline.addLast(new HttpObjectAggregator(CommonConstants.MAX_CONTENT_LENGTH)); } }
Example #30
Source File: ClientInitializer.java From nuls-v2 with MIT License | 5 votes |
@Override protected void initChannel(SocketChannel socketChannel) { ChannelPipeline pipeline = socketChannel.pipeline(); //webSocket协议本身是基于http协议的,所以这边也要使用http解编码器 pipeline.addLast(new HttpServerCodec()); //netty是基于分段请求的,HttpObjectAggregator的作用是将请求分段再聚合,参数是聚合字节的最大长度 pipeline.addLast(new HttpObjectAggregator(1024 * 1024 * 1024)); //webSocket定义了传递数据的6中frame类型 //pipeline.addLast("hookedHandler",new ClientHandler()); }