List of usage examples for io.netty.handler.codec.http HttpClientCodec HttpClientCodec
public HttpClientCodec()
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())); }// w ww . j a v a 2 s. c o 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:Http2ClientInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. *//*ww w .j ava 2 s . c om*/ private void configureClearText(SocketChannel ch) { HttpClientCodec sourceCodec = new HttpClientCodec(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); ch.pipeline().addLast(sourceCodec); ch.pipeline().addLast(upgradeHandler); ch.pipeline().addLast(new UpgradeRequestHandler()); ch.pipeline().addLast(new UserEventLogger()); }
From source file:be.yildizgames.module.network.netty.NettyChannelInitializer.java
License:MIT License
@Override protected void initChannel(final SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); switch (factory.getCodec()) { case STRING:/*from w w w.j a v a 2s . c o m*/ pipeline.addLast(new StringEncoder(CharsetUtil.UTF_8)); pipeline.addLast(new StringDecoder(CharsetUtil.UTF_8)); break; case HTTP: pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new ChunkedWriteHandler()); break; case WEBSOCKET: if (this.factory.isServer()) { pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new WebSocketServerProtocolHandler("/websocket")); } else { pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(8192)); } break; default: throw new IllegalArgumentException("Unknown codec: " + factory.getCodec()); } pipeline.addLast("handler", this.factory.create()); }
From source file:bench.netty.HttpClientInitializer.java
License:Apache License
@Override public void initChannel(final SocketChannel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("codec", new HttpClientCodec()); pipeline.addLast("packer", new HttpObjectAggregator(512 * 1024)); pipeline.addLast("handler", new HttpClientHandler()); }
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.control.SimpleControlClient.java
License:Apache License
private void createClient() { client.group(ioWorkerGroup).channel(NioSocketChannel.class).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() { @Override// w w w.j a va 2s . c o m protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // pipeline.addLast("logger", new LoggingHandler(LogLevel.WARN)); pipeline.addLast("http-client", new HttpClientCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(C5ServerConstants.MAX_CALL_SIZE)); pipeline.addLast("encode", new ClientHttpProtostuffEncoder()); pipeline.addLast("decode", new ClientHttpProtostuffDecoder()); pipeline.addLast("translate", new ClientEncodeCommandRequest()); } }); }
From source file:ca.lambtoncollege.netty.webSocket.ClientWebSocket.java
public static void main(String[] args) throws Exception { URI uri = new URI(URL); String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost(); final int port; if (uri.getPort() == -1) { if ("http".equalsIgnoreCase(scheme)) { port = 80;/*from ww w .ja v a2 s. co m*/ } else if ("https".equalsIgnoreCase(scheme)) { port = 443; } else { port = -1; } } else { port = uri.getPort(); } if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) { System.err.println("Only WS(S) is supported."); return; } final boolean ssl = "wss".equalsIgnoreCase(scheme); final SslContext sslCtx; if (ssl) { sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE); } else { sslCtx = null; } EventLoopGroup group = new NioEventLoopGroup(); try { // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. // If you change it to V00, ping is not supported and remember to change // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline. final ClientHandlerWebSocket handler = new ClientHandlerWebSocket(WebSocketClientHandshakerFactory .newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())); Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc(), host, port)); } p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), handler); } }); Channel ch = b.connect(uri.getHost(), port).sync().channel(); handler.handshakeFuture().sync(); BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); while (true) { String msg = console.readLine(); if (msg == null) { break; } else if ("bye".equals(msg.toLowerCase())) { ch.writeAndFlush(new CloseWebSocketFrame()); ch.closeFuture().sync(); break; } else if ("ping".equals(msg.toLowerCase())) { WebSocketFrame frame = new PingWebSocketFrame( Unpooled.wrappedBuffer(new byte[] { 8, 1, 8, 1 })); ch.writeAndFlush(frame); } else { WebSocketFrame frame = new TextWebSocketFrame(msg); ch.writeAndFlush(frame); } } } finally { group.shutdownGracefully(); } }
From source file:cc.blynk.integration.model.websocket.AppWebSocketClient.java
License:Apache License
@Override public ChannelInitializer<SocketChannel> getChannelInitializer() { return new ChannelInitializer<SocketChannel>() { @Override/*from w w w . jav a2 s.c o m*/ public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(sslCtx.newHandler(ch.alloc(), host, port), new HttpClientCodec(), new HttpObjectAggregator(8192), appHandler, new WebAppMessageDecoder(new GlobalStats(), new Limits(new ServerProperties(Collections.emptyMap())))); } }; }
From source file:cc.blynk.integration.model.websocket.WebSocketClient.java
License:Apache License
@Override protected ChannelInitializer<SocketChannel> getChannelInitializer() { return new ChannelInitializer<SocketChannel>() { @Override/*from w ww. jav a2 s. com*/ public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc(), host, port)); } p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), handler, new MessageDecoder(new GlobalStats())); } }; }
From source file:ccwihr.client.t2.Http2ClientInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. *///from www. j a v a 2 s .c om private void configureClearText(SocketChannel ch) { HttpClientCodec sourceCodec = new HttpClientCodec(); Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); ch.pipeline().addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler(), new UserEventLogger()); }