List of usage examples for io.netty.handler.codec.http HttpContentDecompressor HttpContentDecompressor
public HttpContentDecompressor()
From source file:HttpUploadClientIntializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc())); }//from w w w . ja v a 2 s .co m pipeline.addLast("codec", new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. pipeline.addLast("inflater", new HttpContentDecompressor()); // to be used since huge file transfer pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("handler", new HttpUploadClientHandler()); }
From source file:com.andrewkroh.cisco.xmlservices.HttpClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline p = ch.pipeline();/*from w w w . j a v a 2 s .c om*/ // Create a logger for debugging purposes: p.addLast("log", new LoggingHandler(LogLevel.INFO)); // Adds codec for handling HTTP messages: p.addLast("codec", new HttpClientCodec()); // Add decompresser for GZIP'ed messages: p.addLast("inflater", new HttpContentDecompressor()); // Add automatic handling of "chunked" HTTP messages: p.addLast("aggregator", new HttpObjectAggregator(1048576)); // Finally add our handler: p.addLast("handler", handler); }
From source file:com.cmz.http.snoop.HttpSnoopClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline();/* ww w . j ava2s .co m*/ // Enable HTTPS if necessary. if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. //p.addLast(new HttpObjectAggregator(1048576)); p.addLast(new HttpSnoopClientHandler()); }
From source file:com.difference.historybook.proxy.littleproxy.LittleProxy.java
License:Apache License
private HttpFiltersSource getFiltersSource() { return new HttpFiltersSourceAdapter() { @Override//from w ww . ja va2 s . c om public HttpFilters filterRequest(HttpRequest originalRequest) { return new HttpFiltersAdapter(originalRequest) { private final ProxyFilter filter = filterFactory != null ? filterFactory.getInstance() : null; private EmbeddedChannel bufferChannel = null; @Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (filter != null && httpObject instanceof DefaultHttpRequest) { filter.processRequest(new LittleProxyRequest((DefaultHttpRequest) httpObject)); } return null; } @Override public HttpObject proxyToClientResponse(HttpObject httpObject) { if (httpObject instanceof DefaultHttpResponse) { DefaultHttpResponse response = (DefaultHttpResponse) httpObject; Map<String, String> headers = new HashMap<>(); response.headers().forEach(e -> { headers.put(e.getKey(), e.getValue()); }); if (selector != null && selector.test(new ProxyTransactionInfo(originalRequest.getUri(), response.getStatus().code(), headers))) { bufferChannel = new EmbeddedChannel(new HttpResponseDecoder(), new HttpContentDecompressor(), new HttpObjectAggregator(maxBufferSize)); DefaultHttpResponse copiedResponse = new DefaultHttpResponse( response.getProtocolVersion(), response.getStatus()); copiedResponse.headers().add(response.headers()); bufferChannel.writeInbound(copiedResponse); } } else if (httpObject instanceof DefaultHttpContent && bufferChannel != null) { DefaultHttpContent httpContent = (DefaultHttpContent) httpObject; bufferChannel.writeInbound(httpContent.copy()); if (ProxyUtils.isLastChunk(httpObject)) processChunkedResponse(); } else if (httpObject instanceof LastHttpContent && bufferChannel != null) { LastHttpContent httpContent = (LastHttpContent) httpObject; bufferChannel.writeInbound(httpContent.copy()); processChunkedResponse(); } else if (filter != null && httpObject instanceof FullHttpResponse) { filter.processResponse(new LittleProxyResponse((FullHttpResponse) httpObject)); } return httpObject; }; private void processChunkedResponse() { bufferChannel.flush(); bufferChannel.finish(); FullHttpResponse fullResponse = (FullHttpResponse) bufferChannel.readInbound(); filter.processResponse(new LittleProxyResponse(fullResponse)); bufferChannel = null; } }; }; }; }
From source file:com.dwarf.netty.guide.http.snoop.HttpSnoopClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline();//w w w . j av a 2 s . c om // Enable HTTPS if necessary. if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } //p.addLast(new HttpClientCodec()); p.addLast(new HttpRequestEncoder()); p.addLast(new HttpResponseDecoder()); // Remove the following line if you don't want automatic content decompression. p.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. //p.addLast(new HttpObjectAggregator(1048576)); p.addLast(new HttpSnoopClientHandler()); }
From source file:com.ebay.jetstream.http.netty.client.HttpClient.java
License:MIT License
private void createChannelPipeline() { if (isPipelineCreated()) return;/* ww w .ja v a 2 s. c om*/ m_workerGroup = new NioEventLoopGroup(getConfig().getNumWorkers(), new NameableThreadFactory("Jetstream-HttpClientWorker")); m_bootstrap = new Bootstrap(); m_bootstrap.group(m_workerGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_KEEPALIVE, false) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConfig().getConnectionTimeoutInSecs()) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("timeout", new IdleStateHandler(0, getConfig().getIdleTimeoutInSecs(), 0)); ch.pipeline().addLast("decoder", new HttpResponseDecoder()); ch.pipeline().addLast("decompressor", new HttpContentDecompressor()); ch.pipeline().addLast("encoder", new HttpRequestEncoder()); ch.pipeline().addLast("aggregator", new HttpObjectAggregator(m_config.getMaxContentLength())); ch.pipeline().addLast(m_httpRequestHandler); } }); if (getConfig().getRvcBufSz() > 0) { m_bootstrap.option(ChannelOption.SO_RCVBUF, (int) getConfig().getRvcBufSz()); } if (getConfig().getSendBufSz() > 0) { m_bootstrap.option(ChannelOption.SO_SNDBUF, (int) getConfig().getSendBufSz()); } createdPipeline(); }
From source file:com.ebay.jetstream.http.netty.server.Acceptor.java
License:MIT License
/** * @param rxSessionHandler// w w w.ja v a2 s.com * @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.github.picto.network.exemple.HttpSnoopClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline();//w ww . j a v a 2 s . c o m // Enable HTTPS if necessary. if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. //p.addLast(new HttpObjectAggregator(1048576)); p.addLast(new HttpSnoopClientHandler(shouldEnd)); }
From source file:com.gw.services.client.HttpsClientInitializer.java
License:Apache License
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline();//from w w w. jav a2 s. c o m // Enable HTTPS if necessary. if (sslCtx != null) { SSLEngine sslEngine = sslCtx.createSSLEngine(); sslEngine.setUseClientMode(true); SslHandler sslHandler = new SslHandler(sslEngine); p.addLast(sslHandler); } p.addLast(new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. //p.addLast(new HttpObjectAggregator(1048576)); p.addLast(new HttpsClientHandler()); }
From source file:com.heliosapm.streams.metrichub.HubManager.java
License:Apache License
/** * {@inheritDoc}//from ww w . j a v a2 s . c o m * @see io.netty.channel.pool.ChannelPoolHandler#channelCreated(io.netty.channel.Channel) */ @Override public void channelCreated(final Channel ch) throws Exception { log.debug("Channel Created: {}", ch); channelGroup.add(ch); final ChannelPipeline p = ch.pipeline(); //p.addLast("timeout", new IdleStateHandler(0, 0, 60)); // TODO: configurable p.addLast("httpcodec", new HttpClientCodec()); p.addLast("inflater", new HttpContentDecompressor()); // p.addLast("deflater", new HttpContentCompressor()); p.addLast("aggregator", new HttpObjectAggregator(20485760)); // p.addLast("logging", loggingHandler); p.addLast("qdecoder", queryResultDecoder); }