Example usage for io.netty.channel ChannelPipeline addLast

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

Introduction

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

Prototype

ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers);

Source Link

Document

Inserts ChannelHandler s at the last position of this pipeline.

Usage

From source file:com.eucalyptus.auth.euare.identity.ws.IdentityClientChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(final SocketChannel socketChannel) throws Exception {
    super.initChannel(socketChannel);
    final ChannelPipeline pipeline = socketChannel.pipeline();
    pipeline.addLast("decoder", IoHandlers.httpResponseDecoder());
    pipeline.addLast("aggregator", IoHandlers.newHttpChunkAggregator());
    pipeline.addLast("encoder", IoHandlers.httpRequestEncoder());
    pipeline.addLast("wrapper", IoHandlers.ioMessageWrappingHandler());
    pipeline.addLast("serializer", IoHandlers.soapMarshalling());
    pipeline.addLast("wssec", IoHandlers.internalWsSecHandler());
    pipeline.addLast("addressing", IoHandlers.addressingHandler());
    pipeline.addLast("soap", IoHandlers.soapHandler());
    pipeline.addLast("binding", IoHandlers.bindingHandler("www_eucalyptus_com_ns_identity_2016_10_01"));
    pipeline.addLast("ssl-detection-handler", new IoHandlers.ClientSslHandler("ssl-handler") {
        @Override/* w w  w .j a v  a2s .  c o m*/
        protected SSLEngine createSSLEngine(final String peerHost, final int peerPort) {
            return getSSLEngine(peerHost, peerPort);
        }
    });
    pipeline.addLast("remote", new RemotePathHandler());
}

From source file:com.eucalyptus.cluster.proxy.ws.GatherLogClientChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(final SocketChannel socketChannel) throws Exception {
    final ChannelPipeline pipeline = socketChannel.pipeline();
    addMonitoringHandlers(pipeline, 120);
    pipeline.addLast("decoder", IoHandlers.httpResponseDecoder());
    pipeline.addLast("aggregator", IoHandlers.newHttpChunkAggregator());
    pipeline.addLast("encoder", IoHandlers.httpRequestEncoder());
    pipeline.addLast("wrapper", IoHandlers.ioMessageWrappingHandler());
    pipeline.addLast("serializer", IoHandlers.soapMarshalling());
    pipeline.addLast("addressing", IoHandlers.addressingHandler("EucalyptusGL#"));
    pipeline.addLast("soap", IoHandlers.soapHandler());
    pipeline.addLast("binding", IoHandlers.bindingHandler("eucalyptus_ucsb_edu"));
}

From source file:com.eucalyptus.cluster.proxy.ws.ProxyClusterClientChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(final SocketChannel socketChannel) throws Exception {
    super.initChannel(socketChannel);
    final ChannelPipeline pipeline = socketChannel.pipeline();
    pipeline.addLast("decoder", IoHandlers.httpResponseDecoder());
    pipeline.addLast("aggregator", IoHandlers.newHttpChunkAggregator());
    pipeline.addLast("encoder", IoHandlers.httpRequestEncoder());
    pipeline.addLast("wrapper", IoHandlers.ioMessageWrappingHandler());
    pipeline.addLast("serializer", IoHandlers.soapMarshalling());
    pipeline.addLast("wssec", wsSecHandler.get());
    pipeline.addLast("addressing", IoHandlers.addressingHandler("EucalyptusCC#"));
    pipeline.addLast("soap", IoHandlers.soapHandler());
    pipeline.addLast("binding", IoHandlers.bindingHandler("eucalyptus_ucsb_edu"));
}

From source file:com.eucalyptus.cluster.service.ws.NodeClientChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(final SocketChannel socketChannel) throws Exception {
    super.initChannel(socketChannel);
    final ChannelPipeline pipeline = socketChannel.pipeline();
    pipeline.addLast("decoder", IoHandlers.httpResponseDecoder());
    pipeline.addLast("aggregator", IoHandlers.newHttpChunkAggregator());
    pipeline.addLast("encoder", IoHandlers.httpRequestEncoder());
    pipeline.addLast("wrapper", IoHandlers.ioMessageWrappingHandler());
    pipeline.addLast("serializer", IoHandlers.soapMarshalling());
    pipeline.addLast("wssec", wsSecHandler.get());
    pipeline.addLast("addressing", IoHandlers.addressingHandler("EucalyptusNC#"));
    pipeline.addLast("soap", IoHandlers.soapHandler());
    pipeline.addLast("binding", IoHandlers.bindingHandler("eucalyptus_ucsb_edu"));
}

From source file:com.eucalyptus.ws.client.InternalClientChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(final SocketChannel channel) throws Exception {
    super.initChannel(channel);
    final ChannelPipeline pipeline = channel.pipeline();
    if (MoreObjects.firstNonNull(SslSetup.CLIENT_HTTPS_ENABLED, true)) {
        pipeline.addLast("https", IoHandlers.internalHttpsHandler());
    }/*from w w w  .ja v a 2s. com*/
    pipeline.addLast("decoder", IoHandlers.httpResponseDecoder());
    pipeline.addLast("aggregator", IoHandlers.newHttpChunkAggregator());
    pipeline.addLast("encoder", IoHandlers.httpRequestEncoder());
    pipeline.addLast("wrapper", IoHandlers.ioMessageWrappingHandler());
    if (MoreObjects.firstNonNull(StackConfiguration.CLIENT_INTERNAL_HMAC_SIGNATURE_ENABLED, false)) {
        pipeline.addLast("hmac", IoHandlers.getInternalHmacHandler());
        pipeline.addLast("serializer", IoHandlers.soapMarshalling());
    } else {
        pipeline.addLast("serializer", IoHandlers.soapMarshalling());
        pipeline.addLast("wssec", IoHandlers.internalWsSecHandler());
    }
    pipeline.addLast("addressing", IoHandlers.addressingHandler());
    pipeline.addLast("soap", IoHandlers.soapHandler());
    pipeline.addLast("binding", IoHandlers.bindingHandler());
}

From source file:com.eucalyptus.ws.client.MonitoredSocketChannelInitializer.java

License:Open Source License

protected void addMonitoringHandlers(final ChannelPipeline pipeline, final int timeoutSeconds) {
    final Map<String, ChannelHandler> handlers = IoHandlers.channelMonitors(TimeUnit.SECONDS, timeoutSeconds);
    for (Map.Entry<String, ChannelHandler> e : handlers.entrySet()) {
        pipeline.addLast(e.getKey(), e.getValue());
    }//from   ww  w .  j  a v  a2 s  .c om
}

From source file:com.example.grpc.server.PrometheusServer.java

License:Apache License

public void start() {
    final ServerBootstrap bootstrap = new ServerBootstrap();

    bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override//  ww w .  j  av a  2s.c  o  m
                protected void initChannel(SocketChannel socketChannel) throws Exception {
                    ChannelPipeline pipeline = socketChannel.pipeline();
                    pipeline.addLast("decoder", new HttpRequestDecoder());
                    pipeline.addLast("encoder", new HttpResponseEncoder());
                    pipeline.addLast("prometheus", new SimpleChannelInboundHandler<Object>() {
                        @Override
                        protected void channelRead0(ChannelHandlerContext channelHandlerContext, Object o)
                                throws Exception {
                            if (!(o instanceof HttpRequest)) {
                                return;
                            }

                            HttpRequest request = (HttpRequest) o;

                            if (!"/metrics".equals(request.uri())) {
                                final FullHttpResponse response = new DefaultFullHttpResponse(
                                        HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
                                channelHandlerContext.writeAndFlush(response)
                                        .addListener(ChannelFutureListener.CLOSE);
                                return;
                            }

                            if (!HttpMethod.GET.equals(request.method())) {
                                final FullHttpResponse response = new DefaultFullHttpResponse(
                                        HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_ACCEPTABLE);
                                channelHandlerContext.writeAndFlush(response)
                                        .addListener(ChannelFutureListener.CLOSE);
                                return;
                            }

                            ByteBuf buf = Unpooled.buffer();
                            ByteBufOutputStream os = new ByteBufOutputStream(buf);
                            OutputStreamWriter writer = new OutputStreamWriter(os);
                            TextFormat.write004(writer, registry.metricFamilySamples());
                            writer.close();
                            os.close();

                            final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
                                    HttpResponseStatus.OK, buf);
                            response.headers().set(HttpHeaderNames.CONTENT_TYPE, TextFormat.CONTENT_TYPE_004);
                            channelHandlerContext.writeAndFlush(response)
                                    .addListener(ChannelFutureListener.CLOSE);
                        }
                    });

                }
            });

    try {
        this.channel = bootstrap.bind(this.port).sync().channel();
    } catch (InterruptedException e) {
        // do nothing
    }
}

From source file:com.flysoloing.learning.network.netty.portunification.PortUnificationServerHandler.java

License:Apache License

private void enableSsl(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("ssl", sslCtx.newHandler(ctx.alloc()));
    p.addLast("unificationA", new PortUnificationServerHandler(sslCtx, false, detectGzip));
    p.remove(this);
}

From source file:com.flysoloing.learning.network.netty.portunification.PortUnificationServerHandler.java

License:Apache License

private void enableGzip(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("gzipdeflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
    p.addLast("gzipinflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
    p.addLast("unificationB", new PortUnificationServerHandler(sslCtx, detectSsl, false));
    p.remove(this);
}

From source file:com.flysoloing.learning.network.netty.portunification.PortUnificationServerHandler.java

License:Apache License

private void switchToHttp(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("decoder", new HttpRequestDecoder());
    p.addLast("encoder", new HttpResponseEncoder());
    p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
    p.remove(this);
}