Example usage for io.netty.channel ChannelPipeline context

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

Introduction

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

Prototype

ChannelHandlerContext context(Class<? extends ChannelHandler> handlerType);

Source Link

Document

Returns the context object of the ChannelHandler of the specified type in this pipeline.

Usage

From source file:org.jfxvnc.net.rfb.codec.security.RfbSecurityHandshaker.java

License:Apache License

public final ChannelFuture handshake(Channel channel, boolean sendResponse, ChannelPromise promise) {
    ChannelPipeline p = channel.pipeline();
    ChannelHandlerContext ctx = p.context(RfbClientDecoder.class);
    p.addBefore(ctx.name(), "rfb-security-decoder", newSecurityDecoder());

    ChannelHandlerContext ctx2 = p.context(RfbClientEncoder.class);
    p.addBefore(ctx2.name(), "rfb-security-encoder", newSecurityEncoder());
    if (!sendResponse) {
        return promise.setSuccess();
    }/*from  w w w .  j a  va  2s.  com*/
    channel.writeAndFlush(Unpooled.buffer(1).writeByte(securityType.getType()), promise);
    return promise;
}

From source file:org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession.java

License:Apache License

/**
 * Insert an {@link WebSocketFrameAggregator} after the
 * {@code WebSocketFrameDecoder} for receiving full messages.
 * @param channel the channel for the session
 * @param frameDecoderName the name of the WebSocketFrame decoder
 *//*from   w  w w .  j a  v a  2  s. co m*/
public RxNettyWebSocketSession aggregateFrames(Channel channel, String frameDecoderName) {
    ChannelPipeline pipeline = channel.pipeline();
    if (pipeline.context(FRAME_AGGREGATOR_NAME) != null) {
        return this;
    }
    ChannelHandlerContext frameDecoder = pipeline.context(frameDecoderName);
    if (frameDecoder == null) {
        throw new IllegalArgumentException("WebSocketFrameDecoder not found: " + frameDecoderName);
    }
    ChannelHandler frameAggregator = new WebSocketFrameAggregator(DEFAULT_FRAME_MAX_SIZE);
    pipeline.addAfter(frameDecoder.name(), FRAME_AGGREGATOR_NAME, frameAggregator);
    return this;
}

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
 *///from w w  w.j a va2 s .co  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);//  w w w .  j  a va2  s .c  o m
    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());
}

From source file:sailfish.remoting.handler.NegotiateChannelHandler.java

License:Apache License

@SuppressWarnings("deprecation")
private void remove(ChannelHandlerContext ctx) {
    try {/*from   w  ww . j  ava  2s. c  o m*/
        ctx.channel().attr(OneTime.channelConfig).remove();
        ChannelPipeline pipeline = ctx.pipeline();
        if (pipeline.context(this) != null) {
            pipeline.remove(this);
        }
    } finally {
        negotiateMap.remove(ctx);
    }
}