List of usage examples for io.netty.handler.codec.http HttpContentDecompressor HttpContentDecompressor
public HttpContentDecompressor(boolean strict)
From source file:io.advantageous.conekt.http.impl.HttpClientImpl.java
License:Open Source License
private void internalConnect(ContextImpl clientContext, int port, String host, Handler<ClientConnection> connectHandler, Handler<Throwable> connectErrorHandler, ConnectionLifeCycleListener listener) { ContextImpl context;// w ww .j av a2s.co m if (clientContext == null) { // Embedded context = vertx.getOrCreateContext(); } else { context = clientContext; } Bootstrap bootstrap = new Bootstrap(); bootstrap.group(context.nettyEventLoop()); bootstrap.channelFactory(new VertxNioSocketChannelFactory()); sslHelper.validate(vertx); bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (options.isSsl()) { pipeline.addLast("ssl", sslHelper.createSslHandler(vertx, true, host, port)); } pipeline.addLast("codec", new HttpClientCodec(4096, 8192, options.getMaxChunkSize(), false, false)); if (options.isTryUseCompression()) { pipeline.addLast("inflater", new HttpContentDecompressor(true)); } if (options.getIdleTimeout() > 0) { pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout())); } pipeline.addLast("handler", new ClientHandler(vertx, context)); } }); applyConnectionOptions(bootstrap); ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)); future.addListener((ChannelFuture channelFuture) -> { Channel ch = channelFuture.channel(); if (channelFuture.isSuccess()) { if (options.isSsl()) { // TCP connected, so now we must do the SSL handshake SslHandler sslHandler = ch.pipeline().get(SslHandler.class); io.netty.util.concurrent.Future<Channel> fut = sslHandler.handshakeFuture(); fut.addListener(fut2 -> { if (fut2.isSuccess()) { connected(context, port, host, ch, connectHandler, connectErrorHandler, listener); } else { SSLHandshakeException sslException = new SSLHandshakeException( "Failed to create SSL connection"); Optional.ofNullable(fut2.cause()).ifPresent(sslException::initCause); connectionFailed(context, ch, connectErrorHandler, sslException, listener); } }); } else { connected(context, port, host, ch, connectHandler, connectErrorHandler, listener); } } else { connectionFailed(context, ch, connectErrorHandler, channelFuture.cause(), listener); } }); }
From source file:io.jsync.http.impl.DefaultHttpClient.java
License:Open Source License
void internalConnect(final Handler<ClientConnection> connectHandler, final Handler<Throwable> connectErrorHandler) { if (bootstrap == null) { // Share the event loop thread to also serve the HttpClient's network traffic. AsyncEventLoopGroup pool = new AsyncEventLoopGroup(); pool.addWorker(actualCtx.getEventLoop()); bootstrap = new Bootstrap(); bootstrap.group(pool);//from ww w . j a va2 s.c om bootstrap.channel(NioSocketChannel.class); tcpHelper.checkSSL(async); bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (tcpHelper.isSSL()) { pipeline.addLast("ssl", tcpHelper.createSslHandler(async, true, host, port)); } pipeline.addLast("codec", new HttpClientCodec(4096, 8192, 8192, false, false)); if (tryUseCompression) { pipeline.addLast("inflater", new HttpContentDecompressor(true)); } pipeline.addLast("handler", new ClientHandler()); } }); } tcpHelper.applyConnectionOptions(bootstrap); ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)); future.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) throws Exception { final Channel ch = channelFuture.channel(); if (channelFuture.isSuccess()) { if (tcpHelper.isSSL()) { // TCP connected, so now we must do the SSL handshake SslHandler sslHandler = ch.pipeline().get(SslHandler.class); Future<Channel> fut = sslHandler.handshakeFuture(); fut.addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(Future<Channel> future) throws Exception { if (future.isSuccess()) { connected(ch, connectHandler); } else { connectionFailed(ch, connectErrorHandler, new SSLHandshakeException("Failed to create SSL connection")); } } }); } else { connected(ch, connectHandler); } } else { connectionFailed(ch, connectErrorHandler, channelFuture.cause()); } } }); }
From source file:io.vertx.core.http.impl.HttpChannelConnector.java
License:Open Source License
private void applyHttp1xConnectionOptions(ChannelPipeline pipeline) { if (options.getLogActivity()) { pipeline.addLast("logging", new LoggingHandler()); }/* w w w . j a v a2s . c o m*/ pipeline.addLast("codec", new HttpClientCodec(options.getMaxInitialLineLength(), options.getMaxHeaderSize(), options.getMaxChunkSize(), false, false, options.getDecoderInitialBufferSize())); if (options.isTryUseCompression()) { pipeline.addLast("inflater", new HttpContentDecompressor(true)); } }
From source file:io.vertx.core.http.impl.HttpClientImpl.java
License:Open Source License
private void internalConnect(ContextImpl context, int port, String host, Handler<ClientConnection> connectHandler, Handler<Throwable> connectErrorHandler, ConnectionLifeCycleListener listener) { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(context.eventLoop()); bootstrap.channelFactory(new VertxNioSocketChannelFactory()); sslHelper.validate(vertx);/*from w w w.j ava 2 s .c o m*/ bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (options.isSsl()) { pipeline.addLast("ssl", sslHelper.createSslHandler(vertx, true, host, port)); } pipeline.addLast("codec", new HttpClientCodec(4096, 8192, 8192, false, false)); if (options.isTryUseCompression()) { pipeline.addLast("inflater", new HttpContentDecompressor(true)); } if (options.getIdleTimeout() > 0) { pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout())); } pipeline.addLast("handler", new ClientHandler(vertx, context)); } }); applyConnectionOptions(bootstrap); ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)); future.addListener((ChannelFuture channelFuture) -> { Channel ch = channelFuture.channel(); if (channelFuture.isSuccess()) { if (options.isSsl()) { // TCP connected, so now we must do the SSL handshake SslHandler sslHandler = ch.pipeline().get(SslHandler.class); io.netty.util.concurrent.Future<Channel> fut = sslHandler.handshakeFuture(); fut.addListener(fut2 -> { if (fut2.isSuccess()) { connected(context, port, host, ch, connectHandler, connectErrorHandler, listener); } else { connectionFailed(context, ch, connectErrorHandler, new SSLHandshakeException("Failed to create SSL connection"), listener); } }); } else { connected(context, port, host, ch, connectHandler, connectErrorHandler, listener); } } else { connectionFailed(context, ch, connectErrorHandler, channelFuture.cause(), listener); } }); }
From source file:io.vertx.core.http.impl.HttpServerImpl.java
License:Open Source License
private void configureHttp1(ChannelPipeline pipeline) { if (logEnabled) { pipeline.addLast("logging", new LoggingHandler()); }//w w w . ja v a2 s . co m if (USE_FLASH_POLICY_HANDLER) { pipeline.addLast("flashpolicy", new FlashPolicyHandler()); } pipeline.addLast("httpDecoder", new HttpRequestDecoder(options.getMaxInitialLineLength(), options.getMaxHeaderSize(), options.getMaxChunkSize(), false)); pipeline.addLast("httpEncoder", new VertxHttpResponseEncoder()); if (options.isDecompressionSupported()) { pipeline.addLast("inflater", new HttpContentDecompressor(true)); } if (options.isCompressionSupported()) { pipeline.addLast("deflater", new HttpChunkContentCompressor(options.getCompressionLevel())); } if (sslHelper.isSSL() || options.isCompressionSupported()) { // only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used. pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); // For large file / sendfile support } if (options.getIdleTimeout() > 0) { pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout())); } pipeline.addLast("handler", new ServerHandler(pipeline.channel())); }
From source file:org.vertx.java.core.http.impl.DefaultHttpClient.java
License:Open Source License
void internalConnect(final Handler<ClientConnection> connectHandler, final Handler<Throwable> connectErrorHandler) { if (bootstrap == null) { // Share the event loop thread to also serve the HttpClient's network traffic. VertxEventLoopGroup pool = new VertxEventLoopGroup(); pool.addWorker(actualCtx.getEventLoop()); bootstrap = new Bootstrap(); bootstrap.group(pool);//from w w w. j a v a 2 s . c om bootstrap.channel(NioSocketChannel.class); tcpHelper.checkSSL(vertx); bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (tcpHelper.isSSL()) { SSLEngine engine = tcpHelper.getSSLContext().createSSLEngine(host, port); if (tcpHelper.isVerifyHost()) { SSLParameters sslParameters = engine.getSSLParameters(); sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); engine.setSSLParameters(sslParameters); } engine.setUseClientMode(true); //We are on the client side of the connection pipeline.addLast("ssl", new SslHandler(engine)); } pipeline.addLast("codec", new HttpClientCodec(4096, 8192, 8192, false, false)); if (tryUseCompression) { pipeline.addLast("inflater", new HttpContentDecompressor(true)); } pipeline.addLast("handler", new ClientHandler()); } }); } tcpHelper.applyConnectionOptions(bootstrap); ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)); future.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) throws Exception { final Channel ch = channelFuture.channel(); if (channelFuture.isSuccess()) { if (tcpHelper.isSSL()) { // TCP connected, so now we must do the SSL handshake SslHandler sslHandler = ch.pipeline().get(SslHandler.class); Future<Channel> fut = sslHandler.handshakeFuture(); fut.addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(Future<Channel> future) throws Exception { if (future.isSuccess()) { connected(ch, connectHandler); } else { connectionFailed(ch, connectErrorHandler, new SSLHandshakeException("Failed to create SSL connection")); } } }); } else { connected(ch, connectHandler); } } else { connectionFailed(ch, connectErrorHandler, channelFuture.cause()); } } }); }