@Override public ChannelPipeline addAfter(EventExecutorGroup group, String baseName, String name, ChannelHandler handler) { delegate.addAfter(group, baseName, name, handler); return this; }
@Override public ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler) { delegate.addAfter(baseName, name, handler); return this; }
public void addLoggingHandler(ChannelHandlerContext ctx) { if (ctx.pipeline().get(LoggingHandler.class) != null) { ctx.pipeline().remove(LoggingHandler.class); } if (ctx.pipeline().get(SslHandler.class) != null) { ctx.pipeline().addAfter("SslHandler#0", "LoggingHandler#0", this); } else { ctx.pipeline().addFirst(this); } }
private void registerMicronautChannelHandlers(ChannelPipeline pipeline) { int i = 0; for (ChannelHandler outboundHandlerAdapter : outboundHandlers) { String name; if (outboundHandlerAdapter instanceof Named) { name = ((Named) outboundHandlerAdapter).getName(); } else { name = NettyHttpServer.MICRONAUT_HANDLER + NettyHttpServer.OUTBOUND_KEY + ++i; } pipeline.addAfter(NettyHttpServer.HTTP_CODEC, name, outboundHandlerAdapter); } }
@Override public ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler) { pipeline.addAfter(baseName, name, handler); return this; }
@Override public ChannelPipeline addAfter(EventExecutorGroup group, String baseName, String name, ChannelHandler handler) { pipeline.addAfter(group, baseName, name, handler); return this; }
private void chunkHandler(final ChannelPipeline pipeline) { if (pipeline.get("chunker") == null) { pipeline.addAfter("codec", "chunker", new ChunkedWriteHandler()); } }
/** * Replaces this entry of handler in the netty pipeline with the provided SslHandler and maintains the handler name * * @param sslHandler configured netty handler that enables TLS */ private void replaceSelfWith( SslHandler sslHandler ) { String myName = pipeline.toMap() .entrySet() .stream() .filter( entry -> this.equals( entry.getValue() ) ) .map( Map.Entry::getKey ) .findFirst() .orElseThrow( () -> new IllegalStateException( "This handler has no name" ) ); pipeline.replace( this, myName, sslHandler ); pipeline.addAfter( myName, "handshakeCompletionSslDetailsHandler", new HandshakeCompletionSslDetailsHandler() ); }
protected void releaseHandlers(PooledConnection conn) { final ChannelPipeline pipeline = conn.getChannel().pipeline(); removeHandlerFromPipeline(OriginResponseReceiver.CHANNEL_HANDLER_NAME, pipeline); pipeline.addAfter(PassportStateHttpClientHandler.PASSPORT_STATE_HTTP_CLIENT_HANDLER_NAME, IDLE_STATE_HANDLER_NAME, new IdleStateHandler(0, 0, connPoolConfig.getIdleTimeout(), TimeUnit.MILLISECONDS)); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { for (WebSocketServerExtension extension : validExtensions) { WebSocketExtensionDecoder decoder = extension.newExtensionDecoder(); WebSocketExtensionEncoder encoder = extension.newExtensionEncoder(); ctx.pipeline().addAfter(ctx.name(), decoder.getClass().getName(), decoder); ctx.pipeline().addAfter(ctx.name(), encoder.getClass().getName(), encoder); } } ctx.pipeline().remove(ctx.name()); } });
@Override public void upgradeTo(ChannelHandlerContext ctx, FullHttpResponse upgradeResponse) throws Exception { // Add the handler to the pipeline. ctx.pipeline().addAfter(ctx.name(), handlerName, upgradeToHandler); // Reserve local stream 1 for the response. connectionHandler.onHttpClientUpgrade(); }
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.addAfter(WS_ENCODER_HANDLER, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, config.isEnableWebSocketCompression(), config.getWebSocketMaxFrameSize())); if (config.isAggregateWebSocketFrameFragments()) { pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize())); } pipeline.remove(HTTP_CLIENT_CODEC); }
private String addAfter(ChannelPipeline p, String baseName, ChannelHandler handler) { p.addAfter(baseName, null, handler); return p.context(handler).name(); } }
private String addAfter(final ChannelPipeline p, final String baseName, final String name, final ChannelHandler h) { p.addAfter(baseName, name, h); return p.context(h).name(); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int i = in.readInt(); System.out.println("decoder1 read int (4 bytes). Needs no more: " + Integer.toHexString(i)); ctx.pipeline().addAfter("decoder1", "decoder2", decoder2); ctx.pipeline().addAfter("decoder2", "decoder3", decoder3); ctx.pipeline().remove(this); }
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. // "Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)"); ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); pipeline.addAfter(thisCtx.name(), null, new JerseyServerHandler(baseUri, container)); pipeline.replace(this, null, new ChunkedWriteHandler()); ctx.fireChannelRead(msg); } });
protected void releaseHandlers(PooledConnection conn) { final ChannelPipeline pipeline = conn.getChannel().pipeline(); removeHandlerFromPipeline(OriginResponseReceiver.CHANNEL_HANDLER_NAME, pipeline); pipeline.addAfter(PassportStateHttpClientHandler.PASSPORT_STATE_HTTP_CLIENT_HANDLER_NAME, IDLE_STATE_HANDLER_NAME, new IdleStateHandler(0, 0, connPoolConfig.getIdleTimeout(), TimeUnit.MILLISECONDS)); }
public Future<Channel> updatePipelineForHttpTunneling(ChannelPipeline pipeline, Uri requestUri) { Future<Channel> whenHanshaked = null; if (pipeline.get(HTTP_CLIENT_CODEC) != null) pipeline.remove(HTTP_CLIENT_CODEC); if (requestUri.isSecured()) { if (!isSslHandlerConfigured(pipeline)) { SslHandler sslHandler = createSslHandler(requestUri.getHost(), requestUri.getExplicitPort()); whenHanshaked = sslHandler.handshakeFuture(); pipeline.addBefore(INFLATER_HANDLER, SSL_HANDLER, sslHandler); } pipeline.addAfter(SSL_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec()); } else { pipeline.addBefore(AHC_HTTP_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec()); } if (requestUri.isWebSocket()) { pipeline.addAfter(AHC_HTTP_HANDLER, AHC_WS_HANDLER, wsHandler); pipeline.remove(AHC_HTTP_HANDLER); } return whenHanshaked; }
@Override public final void call(final ChannelPipeline pipeline) { final SslHandler sslHandler = newSslHandler(pipeline); ChannelHandler wireLogging = pipeline.get(WireLogging.getName()); if (null != wireLogging) { /*So that, all activity on the channel is printed including SSL.*/ pipeline.addAfter(WireLogging.getName(), SslHandler.getName(), sslHandler); } else { pipeline.addFirst(SslHandler.getName(), sslHandler); } pipeline.addAfter(SslHandler.getName(), SslConnectionEmissionHandler.getName(), new SslConnEmissionHandler()); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { try { ProtocolDetectionResult<HAProxyProtocolVersion> result = HAProxyMessageDecoder.detectProtocol((ByteBuf) msg); // TODO - is it possible that this message could be split over multiple ByteBufS, and therefore this would fail? if (result.state() == ProtocolDetectionState.DETECTED) { // Add the actual HAProxy decoder. // Note that the HAProxyMessageDecoder will remove itself once it has finished decoding the initial ProxyProtocol message(s). ctx.pipeline().addAfter(NAME, null, new HAProxyMessageDecoder()); // Remove this handler, as now no longer needed. ctx.pipeline().remove(this); } } catch (Exception e) { if (msg != null) { logger.error("Exception in OptionalHAProxyMessageDecoder {}" + e.getClass().getCanonicalName()); if (dumpHAProxyByteBuf.get()) { logger.error("Exception Stack: {}" + e.getStackTrace()); logger.error("Bytebuf is: {} " + ((ByteBuf) msg).toString(CharsetUtil.US_ASCII)); } ((ByteBuf) msg).release(); } } } super.channelRead(ctx, msg); } }