List of usage examples for io.netty.channel ChannelPipeline addAfter
ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler);
From source file:net.dongliu.prettypb.rpc.server.RequestHandler.java
License:Apache License
private void completePipeline(RpcServerChannel rpcServerChannel) { ChannelPipeline p = rpcServerChannel.getChannel().pipeline(); if (rpcServerChannel.isCompress()) { p.addBefore(Handlers.FRAME_DECODER, Handlers.COMPRESSOR, ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP)); p.addAfter(Handlers.COMPRESSOR, Handlers.DECOMPRESSOR, ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP)); }/*from w w w.j a v a2s.c o m*/ RpcServerHandler rpcServerHandler = new RpcServerHandler(rpcServerChannel, rpcServiceRegistry, rpcServiceExecutor, rpcServerChannelRegistry, extensionRegistry); p.addLast(Handlers.RPC_SERVER, rpcServerHandler); }
From source file:org.apache.hadoop.hbase.security.NettyHBaseRpcConnectionHeaderHandler.java
License:Apache License
/** * Remove handlers for sasl encryption and add handlers for Crypto AES encryption *//*w ww.j a v a 2 s . c om*/ private void setupCryptoAESHandler(ChannelPipeline p, CryptoAES cryptoAES) { p.remove(SaslWrapHandler.class); p.remove(SaslUnwrapHandler.class); String lengthDecoder = p.context(LengthFieldBasedFrameDecoder.class).name(); p.addAfter(lengthDecoder, null, new CryptoAESUnwrapHandler(cryptoAES)); p.addAfter(lengthDecoder, null, new CryptoAESWrapHandler(cryptoAES)); }
From source file:org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer.java
License:Apache License
@Override public void configure(final ChannelPipeline pipeline) { handler.configure(pipeline);// w ww. j a va 2 s.c o m pipeline.addAfter(PIPELINE_HTTP_REQUEST_DECODER, "WsAndHttpChannelizerHandler", handler); }
From source file:org.apache.tinkerpop.gremlin.server.handler.WsAndHttpChannelizerHandler.java
License:Apache License
@Override public void channelRead(final ChannelHandlerContext ctx, final Object obj) { final ChannelPipeline pipeline = ctx.pipeline(); if (obj instanceof HttpMessage && !WebSocketHandlerUtil.isWebSocket((HttpMessage) obj)) { if (null != pipeline.get(PIPELINE_AUTHENTICATOR)) { pipeline.remove(PIPELINE_REQUEST_HANDLER); final ChannelHandler authenticator = pipeline.get(PIPELINE_AUTHENTICATOR); pipeline.remove(PIPELINE_AUTHENTICATOR); pipeline.addAfter(PIPELINE_HTTP_RESPONSE_ENCODER, PIPELINE_AUTHENTICATOR, authenticator); pipeline.addAfter(PIPELINE_AUTHENTICATOR, PIPELINE_REQUEST_HANDLER, this.httpGremlinEndpointHandler); } else {/* w w w. ja va 2 s.c om*/ pipeline.remove(PIPELINE_REQUEST_HANDLER); pipeline.addAfter(PIPELINE_HTTP_RESPONSE_ENCODER, PIPELINE_REQUEST_HANDLER, this.httpGremlinEndpointHandler); } } ctx.fireChannelRead(obj); }
From source file:org.asynchttpclient.netty.channel.ChannelManager.java
License:Open Source License
public void configureBootstraps(NettyRequestSender requestSender) { final AsyncHttpClientHandler httpHandler = new HttpHandler(config, this, requestSender); wsHandler = new WebSocketHandler(config, this, requestSender); final NoopHandler pinnedEntry = new NoopHandler(); final LoggingHandler loggingHandler = new LoggingHandler(LogLevel.TRACE); httpBootstrap.handler(new ChannelInitializer<Channel>() { @Override// www . jav a2 s . c o m protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline()// .addLast(PINNED_ENTRY, pinnedEntry)// .addLast(HTTP_CLIENT_CODEC, newHttpClientCodec())// .addLast(INFLATER_HANDLER, newHttpContentDecompressor())// .addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())// .addLast(AHC_HTTP_HANDLER, httpHandler); if (LOGGER.isTraceEnabled()) { pipeline.addAfter(PINNED_ENTRY, LOGGING_HANDLER, loggingHandler); } if (config.getHttpAdditionalChannelInitializer() != null) config.getHttpAdditionalChannelInitializer().initChannel(ch); } }); wsBootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline()// .addLast(PINNED_ENTRY, pinnedEntry)// .addLast(HTTP_CLIENT_CODEC, newHttpClientCodec())// .addLast(AHC_WS_HANDLER, wsHandler); if (LOGGER.isDebugEnabled()) { pipeline.addAfter(PINNED_ENTRY, LOGGING_HANDLER, loggingHandler); } if (config.getWsAdditionalChannelInitializer() != null) config.getWsAdditionalChannelInitializer().initChannel(ch); } }); }
From source file:org.asynchttpclient.netty.channel.ChannelManager.java
License:Open Source License
public void upgradeProtocol(ChannelPipeline pipeline, Uri requestUri) throws SSLException { if (pipeline.get(HTTP_CLIENT_CODEC) != null) pipeline.remove(HTTP_CLIENT_CODEC); if (requestUri.isSecured()) if (isSslHandlerConfigured(pipeline)) { pipeline.addAfter(SSL_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec()); } else {/*from ww w . j ava 2s .c o m*/ pipeline.addAfter(PINNED_ENTRY, HTTP_CLIENT_CODEC, newHttpClientCodec()); pipeline.addAfter(PINNED_ENTRY, SSL_HANDLER, createSslHandler(requestUri.getHost(), requestUri.getExplicitPort())); } else pipeline.addAfter(PINNED_ENTRY, HTTP_CLIENT_CODEC, newHttpClientCodec()); if (requestUri.isWebSocket()) { pipeline.addAfter(AHC_HTTP_HANDLER, AHC_WS_HANDLER, wsHandler); pipeline.remove(AHC_HTTP_HANDLER); } }
From source file:org.asynchttpclient.netty.channel.ChannelManager.java
License:Open Source License
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.addBefore(AHC_WS_HANDLER, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, config.getWebSocketMaxFrameSize())); pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize())); pipeline.remove(HTTP_CLIENT_CODEC);/* w w w .j av a 2s. c o m*/ }
From source file:org.asynchttpclient.providers.netty.channel.ChannelManager.java
License:Open Source License
public void upgradeProtocol(ChannelPipeline pipeline, String scheme, String host, int port) throws IOException, GeneralSecurityException { if (pipeline.get(HTTP_HANDLER) != null) pipeline.remove(HTTP_HANDLER);//w w w . jav a 2 s . c o m if (isSecure(scheme)) if (isSslHandlerConfigured(pipeline)) { pipeline.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec()); } else { pipeline.addFirst(HTTP_HANDLER, newHttpClientCodec()); pipeline.addFirst(SSL_HANDLER, createSslHandler(host, port)); } else pipeline.addFirst(HTTP_HANDLER, newHttpClientCodec()); if (isWebSocket(scheme)) { pipeline.addAfter(HTTP_PROCESSOR, WS_PROCESSOR, wsProcessor); pipeline.remove(HTTP_PROCESSOR); } }
From source file:org.asynchttpclient.providers.netty.channel.ChannelManager.java
License:Open Source License
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_HANDLER, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.remove(HTTP_HANDLER);//from w w w . j a va 2 s . c o m pipeline.addBefore(WS_PROCESSOR, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, nettyConfig.getWebSocketMaxFrameSize())); pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(nettyConfig.getWebSocketMaxBufferSize())); }
From source file:org.asynchttpclient.providers.netty.channel.Channels.java
License:Apache License
public void upgradeProtocol(ChannelPipeline p, String scheme, String host, int port) throws IOException, GeneralSecurityException { if (p.get(HTTP_HANDLER) != null) { p.remove(HTTP_HANDLER);/*from ww w.j av a 2 s . co m*/ } if (isSecure(scheme)) { if (p.get(SSL_HANDLER) == null) { p.addFirst(HTTP_HANDLER, newHttpClientCodec()); p.addFirst(SSL_HANDLER, createSslHandler(host, port)); } else { p.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec()); } } else { p.addFirst(HTTP_HANDLER, newHttpClientCodec()); } if (isWebSocket(scheme)) { p.replace(HTTP_PROCESSOR, WS_PROCESSOR, wsProcessor); } }