List of usage examples for io.netty.handler.codec.http HttpContentCompressor HttpContentCompressor
public HttpContentCompressor(int compressionLevel)
From source file:com.ebay.jetstream.http.netty.server.Acceptor.java
License:MIT License
/** * @param rxSessionHandler/*from w ww .jav a 2 s. c o m*/ * @throws Exception */ public void bind(final HttpRequestHandler httpReqHandler, final HttpServerStatisticsHandler statisticsHandler) throws Exception { m_bossGroup = new NioEventLoopGroup(1, new NameableThreadFactory("NettyHttpServerAcceptor")); m_workerGroup = new NioEventLoopGroup(m_numIoProcessors, new NameableThreadFactory("NettyHttpServerWorker")); try { m_serverbootstrap = new ServerBootstrap(); m_serverbootstrap.group(m_bossGroup, m_workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("timeout", new IdleStateHandler((int) m_readIdleTimeout, 0, 0)); ch.pipeline().addLast("stats", statisticsHandler); ch.pipeline().addLast("decoder", new HttpRequestDecoder()); ch.pipeline().addLast("encoder", new HttpResponseEncoder()); ch.pipeline().addLast("decompressor", new HttpContentDecompressor()); ch.pipeline().addLast("deflater", new HttpContentCompressor(1)); ch.pipeline().addLast("aggregator", new HttpObjectAggregator(m_maxContentLength)); if (m_maxKeepAliveRequests > 0 || m_maxKeepAliveTimeout > 0) { ch.pipeline().addLast("keepAliveHandler", new KeepAliveHandler(m_maxKeepAliveRequests, m_maxKeepAliveTimeout)); } ch.pipeline().addLast("handler", httpReqHandler); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.SO_KEEPALIVE, false); if (m_config.getRvcBufSz() > 0) { m_serverbootstrap.childOption(ChannelOption.SO_RCVBUF, (int) m_config.getRvcBufSz()); } if (m_config.getSendBufSz() > 0) { m_serverbootstrap.childOption(ChannelOption.SO_SNDBUF, (int) m_config.getSendBufSz()); } } catch (Exception t) { throw t; } m_acceptorSocket = new InetSocketAddress(m_ipAddress, m_tcpPort); m_serverbootstrap.bind(m_acceptorSocket).sync(); if (!m_ipAddress.isLoopbackAddress() && !m_ipAddress.isAnyLocalAddress()) { // Add lookback if not bind m_localAcceptorSocket = new InetSocketAddress("127.0.0.1", m_tcpPort); m_serverbootstrap.bind(m_localAcceptorSocket).sync(); } }
From source file:com.ning.http.client.providers.netty_4.NettyAsyncHttpProvider.java
License:Apache License
protected ChannelInitializer createPlainPipelineFactory() { return new ChannelInitializer() { /* @Override */ protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); if (config.getRequestCompressionLevel() > 0) { pipeline.addLast("deflater", new HttpContentCompressor(config.getRequestCompressionLevel())); }//w w w . jav a 2 s . c o m if (config.isCompressionEnabled()) { pipeline.addLast("inflater", new HttpContentDecompressor()); } pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); } }; }
From source file:io.liveoak.container.protocols.PipelineConfigurator.java
License:Open Source License
public void switchToPlainHttp(ChannelPipeline pipeline) { // turn off automatic socket read for better http body read control pipeline.addLast("channel-resetter", new ChannelResetterHandler(this)); pipeline.channel().config().setAutoRead(false); pipeline.remove(WebSocketHandshakerHandler.class); //pipeline.addLast(new DebugHandler("server-pre-cors")); pipeline.addLast("cors-origin-handler", new CORSHandler()); pipeline.addLast("cors-preflight-handler", new CORSPreflightOptionsHandler()); //pipeline.addLast( new DebugHandler( "server-post-cors" ) ); pipeline.addLast("deflater", new HttpContentCompressor(1)); pipeline.addLast("http-resource-decoder", new HttpResourceRequestDecoder(this.codecManager)); pipeline.addLast("http-resource-encoder", new HttpResourceResponseEncoder(this.codecManager)); pipeline.addLast("http-request-body-handler", new HttpRequestBodyHandler()); pipeline.addLast("interceptor", new InterceptorHandler("http", this.interceptorManager)); pipeline.addLast("request-context-disposer", new RequestContextDisposerHandler()); //pipeline.addLast("auth-handler", new AuthHandler(this.client)); //pipeline.addLast("authz-handler", new AuthzHandler(this.client)); pipeline.addLast("subscription-watcher", new SubscriptionWatcher(this.subscriptionManager)); //pipeline.addLast( new DebugHandler( "server-debug" ) ); pipeline.addLast("resource-state-handler", new ResourceStateHandler(this.workerPool)); pipeline.addLast("object-handler", new ResourceHandler(this.globalContext, this.workerPool)); pipeline.addLast("error-handler", new ErrorHandler()); }
From source file:org.elasticsearch.http.nio.HttpReadWriteHandler.java
License:Apache License
public HttpReadWriteHandler(NioHttpChannel nioHttpChannel, NioHttpServerTransport transport, HttpHandlingSettings settings, NioCorsConfig corsConfig) { this.nioHttpChannel = nioHttpChannel; this.transport = transport; List<ChannelHandler> handlers = new ArrayList<>(5); HttpRequestDecoder decoder = new HttpRequestDecoder(settings.getMaxInitialLineLength(), settings.getMaxHeaderSize(), settings.getMaxChunkSize()); decoder.setCumulator(ByteToMessageDecoder.COMPOSITE_CUMULATOR); handlers.add(decoder);//ww w .j a va2 s.c o m handlers.add(new HttpContentDecompressor()); handlers.add(new HttpResponseEncoder()); handlers.add(new HttpObjectAggregator(settings.getMaxContentLength())); if (settings.isCompression()) { handlers.add(new HttpContentCompressor(settings.getCompressionLevel())); } if (settings.isCorsEnabled()) { handlers.add(new NioCorsHandler(corsConfig)); } handlers.add(new NioHttpPipeliningHandler(transport.getLogger(), settings.getPipeliningMaxEvents())); adaptor = new NettyAdaptor(handlers.toArray(new ChannelHandler[0])); adaptor.addCloseListener((v, e) -> nioHttpChannel.close()); }