Example usage for io.netty.channel ChannelHandlerContext name

List of usage examples for io.netty.channel ChannelHandlerContext name

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext name.

Prototype

String name();

Source Link

Document

The unique name of the ChannelHandlerContext .The name was used when then ChannelHandler was added to the ChannelPipeline .

Usage

From source file:at.yawk.dbus.protocol.auth.AuthClient.java

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    for (ChannelHandler handler : handlers) {
        ctx.pipeline().addBefore(ctx.executor(), ctx.name(), null, handler);
    }/* w  w  w  .  j  a  va 2s.c o  m*/
    super.handlerAdded(ctx);
}

From source file:at.yawk.dbus.protocol.codec.DbusMainProtocol.java

private void add(ChannelHandlerContext ctx, ChannelHandler handler) {
    ctx.pipeline().addBefore(ctx.executor(), ctx.name(), null, handler);
}

From source file:com.addthis.hydra.query.loadbalance.NextQueryTask.java

License:Apache License

private static ChannelHandlerContext cleanPipelineAndGetLastContext(ChannelPipeline pipeline) {
    log.trace("pipeline before pruning {}", pipeline);
    ChannelHandlerContext lastContext = pipeline.lastContext();
    while ((lastContext != null) && !"encoder".equals(lastContext.name())) {
        pipeline.removeLast();/*from ww w  .j a v  a2s . c o  m*/
        lastContext = pipeline.lastContext();
    }
    log.trace("pipeline after pruning {}", pipeline);
    return lastContext;
}

From source file:com.chiorichan.http.ssl.SniNegotiator.java

License:Mozilla Public License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (!handshaken && in.readableBytes() >= 5) {
        String hostname = sniHostNameFromHandshakeInfo(in);
        if (hostname != null)
            hostname = IDN.toASCII(hostname, IDN.ALLOW_UNASSIGNED).toLowerCase(Locale.US);
        this.hostname = hostname;

        selectedContext = SslManager.instance().map(hostname);

        if (handshaken) {
            SSLEngine engine = selectedContext.newEngine(ctx.alloc());

            List<String> supportedCipherSuites = Arrays.asList(engine.getSupportedCipherSuites());

            if (!supportedCipherSuites.containsAll(enabledCipherSuites))
                for (String cipher : enabledCipherSuites)
                    if (!supportedCipherSuites.contains(cipher)) {
                        NetworkManager.getLogger()
                                .severe(String.format(
                                        "The SSL/TLS cipher suite '%s' is not supported by SSL Provider %s",
                                        cipher, SslContext.defaultServerProvider().name()));
                        enabledCipherSuites.remove(cipher);
                    }/* w w  w.j  av  a  2  s.co  m*/

            engine.setUseClientMode(false);
            engine.setEnabledCipherSuites(enabledCipherSuites.toArray(new String[0]));

            ctx.pipeline().replace(this, ctx.name(), new SslExceptionHandler(engine));
        }
    }
}

From source file:com.emin.igwmp.skm.core.netty.handler.SocksServerHandler.java

License:Apache License

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    super.channelInactive(ctx);
    LogUtils.I(":" + ctx.channel().remoteAddress() + "  :" + ctx.name());
}

From source file:com.emin.igwmp.skm.core.netty.handler.SocksServerHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    super.channelActive(ctx);
    try {/*from ww  w . j  a  va 2 s.c  o  m*/
        LogUtils.I(":" + ctx.channel().remoteAddress() + "  :" + ctx.name());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.flysoloing.learning.network.netty.http2.helloworld.multiplex.server.Http2ServerInitializer.java

License:Apache License

/**
 * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0
 *///from  w  ww. j  av  a  2  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.
            System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null,
                    new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
        }
    });

    p.addLast(new UserEventLogger());
}

From source file:com.github.sinsinpub.pero.manual.proxyhandler.HttpProxyServer.java

License:Apache License

private boolean authenticate(ChannelHandlerContext ctx, FullHttpRequest req) {
    assertThat(req.method(), Matchers.is(HttpMethod.CONNECT));

    if (testMode != TestMode.INTERMEDIARY) {
        ctx.pipeline().addBefore(ctx.name(), "lineDecoder", new LineBasedFrameDecoder(64, false, true));
    }//w w  w  .  j  a v a2s  .c  o m

    ctx.pipeline().remove(HttpObjectAggregator.class);
    ctx.pipeline().remove(HttpRequestDecoder.class);

    boolean authzSuccess = false;
    if (username != null) {
        CharSequence authz = req.headers().get(HttpHeaderNames.PROXY_AUTHORIZATION);
        if (authz != null) {
            String[] authzParts = StringUtil.split(authz.toString(), ' ', 2);
            ByteBuf authzBuf64 = Unpooled.copiedBuffer(authzParts[1], CharsetUtil.US_ASCII);
            ByteBuf authzBuf = Base64.decode(authzBuf64);

            String expectedAuthz = username + ':' + password;
            authzSuccess = "Basic".equals(authzParts[0])
                    && expectedAuthz.equals(authzBuf.toString(CharsetUtil.US_ASCII));

            authzBuf64.release();
            authzBuf.release();
        }
    } else {
        authzSuccess = true;
    }

    return authzSuccess;
}

From source file:com.hop.hhxx.example.http2.helloworld.multiplex.server.Http2ServerInitializer.java

License:Apache License

/**
 * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0
 *///  ww w  .j  a va 2  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.
            System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null,
                    new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(msg);
        }
    });

    p.addLast(new UserEventLogger());
}

From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java

License:Apache License

void addBeforeSessionHandler(ChannelPipeline pipeline, ChannelHandler handler) {
    // Get the name of the HttpSessionHandler so that we can put our handlers before it.
    final ChannelHandlerContext lastContext = pipeline.lastContext();
    assert lastContext.handler().getClass() == HttpSessionHandler.class;

    pipeline.addBefore(lastContext.name(), null, handler);
}