Example usage for io.netty.channel ChannelPipeline replace

List of usage examples for io.netty.channel ChannelPipeline replace

Introduction

In this page you can find the example usage for io.netty.channel ChannelPipeline replace.

Prototype

<T extends ChannelHandler> T replace(Class<T> oldHandlerType, String newName, ChannelHandler newHandler);

Source Link

Document

Replaces the ChannelHandler of the specified type with a new handler in this pipeline.

Usage

From source file:org.wso2.custom.inbound.InboundHttp2ServerInitializer.java

License:Apache License

/**
 * Configure the pipeline for a clear text upgrade from HTTP to HTTP/2.0
 */// www  .  j  a  v a  2s.  c  o  m
private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();

    p.addLast(sourceCodec);
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory));
    p.addLast(new SimpleChannelInboundHandler<HttpMessage>() {
        @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.
            log.info("No upgrade done: continue with " + msg.protocolVersion());
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new InboundHttpSourceHandler(config));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(msg);
        }
    });
    p.addLast(new UserEventLogger());
}

From source file:org.wso2.esb.integration.common.utils.servers.http2.Http2ServerInitializer.java

License:Open Source License

private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();

    p.addLast(sourceCodec);//ww w  .j ava2  s .c om
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory));
    p.addLast(new SimpleChannelInboundHandler<HttpMessage>() {
        @Override
        protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new Http1Handler("Direct. No Upgrade Attempted."));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(msg);
        }
    });

    p.addLast(new UserEventLogger());
}