Example usage for io.netty.channel ChannelPipeline get

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

Introduction

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

Prototype

<T extends ChannelHandler> T get(Class<T> handlerType);

Source Link

Document

Returns the ChannelHandler of the specified type in this pipeline.

Usage

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

License:Apache License

private static void incrementLocalWindowSize(ChannelPipeline pipeline, int delta) {
    try {/*w w  w  .j a v a 2  s.  c  om*/
        final Http2Connection connection = pipeline.get(Http2ClientConnectionHandler.class).connection();
        connection.local().flowController().incrementWindowSize(connection.connectionStream(), delta);
    } catch (Http2Exception e) {
        logger.warn("Failed to increment local flowController window size: {}", delta, e);
    }
}

From source file:com.ning.http.client.providers.netty_4.NettyAsyncHttpProvider.java

License:Apache License

private void upgradeProtocol(ChannelPipeline p, String scheme) throws IOException, GeneralSecurityException {
    if (p.get(HTTP_HANDLER) != null) {
        p.remove(HTTP_HANDLER);//from w  ww.j  a  v  a  2s.com
    }

    if (isSecure(scheme)) {
        if (p.get(SSL_HANDLER) == null) {
            p.addFirst(HTTP_HANDLER, newHttpClientCodec());
            p.addFirst(SSL_HANDLER, new SslHandler(createSSLEngine()));
        } else {
            p.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec());
        }

    } else {
        p.addFirst(HTTP_HANDLER, newHttpClientCodec());
    }
}

From source file:com.replaymod.sponge.recording.spongecommon.accessor.SpongeConnectionFromPlayerConnectionAccessor.java

License:MIT License

@Nullable
@Override//from w  w w  .  jav  a  2  s  . com
public SpongeConnection apply(PlayerConnection input) {
    try {
        ChannelPipeline pipeline = ((Channel) channel.get(netManager.get(input))).pipeline();
        SpongeConnectionEventListener handler = pipeline.get(SpongeConnectionEventListener.class);
        return handler == null ? null : handler.getConnection();
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.advantageous.conekt.http.impl.ClientConnection.java

License:Open Source License

NetSocket createNetSocket() {
    // connection was upgraded to raw TCP socket
    NetSocketImpl socket = new NetSocketImpl(vertx, channel, context, client.getSslHelper(), true, metrics,
            metric);//w w w.j  a  v a2s  .c  o m
    Map<Channel, NetSocketImpl> connectionMap = new HashMap<>(1);
    connectionMap.put(channel, socket);

    // Flush out all pending data
    endReadAndFlush();

    // remove old http handlers and replace the old handler with one that handle plain sockets
    ChannelPipeline pipeline = channel.pipeline();
    ChannelHandler inflater = pipeline.get(HttpContentDecompressor.class);
    if (inflater != null) {
        pipeline.remove(inflater);
    }
    pipeline.remove("codec");
    pipeline.replace("handler", "handler", new ConektNetHandler(connectionMap) {
        @Override
        public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception {
            // remove from the real mapping
            client.removeChannel(channel);
            super.exceptionCaught(chctx, t);
        }

        @Override
        public void channelInactive(ChannelHandlerContext chctx) throws Exception {
            // remove from the real mapping
            client.removeChannel(channel);
            super.channelInactive(chctx);
        }

        @Override
        public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception {
            if (msg instanceof HttpContent) {
                ReferenceCountUtil.release(msg);
                return;
            }
            super.channelRead(chctx, msg);
        }
    });
    return socket;
}

From source file:io.advantageous.conekt.http.impl.HttpServerImpl.java

License:Open Source License

private String getWebSocketLocation(ChannelPipeline pipeline, HttpRequest req) throws Exception {
    String prefix;/*from  w  w w.  ja v  a  2s  .com*/
    if (pipeline.get(SslHandler.class) == null) {
        prefix = "ws://";
    } else {
        prefix = "wss://";
    }
    URI uri = new URI(req.getUri());
    String path = uri.getRawPath();
    String loc = prefix + HttpHeaders.getHost(req) + path;
    String query = uri.getRawQuery();
    if (query != null) {
        loc += "?" + query;
    }
    return loc;
}

From source file:io.advantageous.conekt.http.impl.ServerConnection.java

License:Open Source License

NetSocket createNetSocket() {
    NetSocketImpl socket = new NetSocketImpl(vertx, channel, context, server.getSslHelper(), false, metrics,
            metric);/*from   w w w .  ja  v a 2  s  .c om*/
    Map<Channel, NetSocketImpl> connectionMap = new HashMap<>(1);
    connectionMap.put(channel, socket);

    // Flush out all pending data
    endReadAndFlush();

    // remove old http handlers and replace the old handler with one that handle plain sockets
    ChannelPipeline pipeline = channel.pipeline();
    ChannelHandler compressor = pipeline.get(HttpChunkContentCompressor.class);
    if (compressor != null) {
        pipeline.remove(compressor);
    }

    pipeline.remove("httpDecoder");
    if (pipeline.get("chunkedWriter") != null) {
        pipeline.remove("chunkedWriter");
    }

    channel.pipeline().replace("handler", "handler", new ConektNetHandler(connectionMap) {
        @Override
        public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception {
            // remove from the real mapping
            server.removeChannel(channel);
            super.exceptionCaught(chctx, t);
        }

        @Override
        public void channelInactive(ChannelHandlerContext chctx) throws Exception {
            // remove from the real mapping
            server.removeChannel(channel);
            super.channelInactive(chctx);
        }

        @Override
        public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception {
            if (msg instanceof HttpContent) {
                ReferenceCountUtil.release(msg);
                return;
            }
            super.channelRead(chctx, msg);
        }
    });

    // check if the encoder can be removed yet or not.
    if (lastWriteFuture == null) {
        channel.pipeline().remove("httpEncoder");
    } else {
        lastWriteFuture.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                channel.pipeline().remove("httpEncoder");
            }
        });
    }
    return socket;
}

From source file:io.cettia.asity.bridge.netty4.AsityServerCodec.java

License:Apache License

private String getWebSocketLocation(ChannelPipeline pipeline, HttpRequest req) {
    return (pipeline.get(SslHandler.class) == null ? "ws://" : "wss://") + HttpHeaders.getHost(req)
            + req.getUri();//from  ww  w.  jav  a  2  s . co  m
}

From source file:io.gatling.http.client.impl.DefaultHttpClient.java

License:Apache License

private Future<Channel> installSslHandler(HttpTx tx, Channel channel) {

    SslContext sslCtx = tx.request.isAlpnRequired() ? alpnSslContext : sslContext;

    try {// w ww. j a v  a 2s.  c o m
        SslHandler sslHandler = SslHandlers.newSslHandler(sslCtx, channel.alloc(), tx.request.getUri(),
                tx.request.getVirtualHost(), config);
        tx.listener.onTlsHandshakeAttempt();

        ChannelPipeline pipeline = channel.pipeline();
        String after = pipeline.get(PROXY_HANDLER) != null ? PROXY_HANDLER : PINNED_HANDLER;
        pipeline.addAfter(after, SSL_HANDLER, sslHandler);

        return sslHandler.handshakeFuture().addListener(f -> {

            SSLSession sslSession = sslHandler.engine().getHandshakeSession();
            if (sslSession != null && sslSession.isValid() && config.isDisableSslSessionResumption()) {
                sslSession.invalidate();
            }

            if (tx.requestTimeout.isDone()) {
                return;
            }

            if (f.isSuccess()) {
                tx.listener.onTlsHandshakeSuccess();
            } else {
                tx.requestTimeout.cancel();
                tx.listener.onTlsHandshakeFailure(f.cause());
                tx.listener.onThrowable(f.cause());
            }
        });
    } catch (RuntimeException e) {
        tx.requestTimeout.cancel();
        tx.listener.onThrowable(e);
        return new DefaultPromise<Channel>(ImmediateEventExecutor.INSTANCE).setFailure(e);
    }
}

From source file:io.github.vastframework.codecs.handlers.Handlers.java

License:Apache License

/**
 * Sets the CodecProvider of all ChannelHandlers created by this class in the given
 * ChannelPipeline./*  w  w  w  .ja v  a  2  s  . c  o  m*/
 *
 * @param pipeline the pipeline, in which the ChannelHandlers, whose CodecProvider has to be set,
 *     are contained
 * @param codecProvider the CodecProvider to set
 */
public static void setCodecProvider(@NotNull ChannelPipeline pipeline, @NotNull CodecProvider codecProvider) {
    checkNotNull(codecProvider, "codecProvider cannot be null");
    checkNotNull(pipeline, "pipeline cannot be null");

    CodecBasedEncoder encoder = pipeline.get(CodecBasedEncoder.class);
    if (encoder != null) {
        encoder.setCodecProvider(codecProvider);
    }
    CodecBasedDecoder decoder = pipeline.get(CodecBasedDecoder.class);
    if (decoder != null) {
        decoder.setCodecProvider(codecProvider);
    }
}

From source file:io.higgs.http.client.ClientIntializer.java

License:Apache License

public void configurePipeline(ChannelPipeline pipeline) {
    if (ssl) {/*from   w  w w  .j a v  a2  s  .c om*/
        addSSL(pipeline, false, sslProtocols);
    }

    if (pipeline.get("codec") == null) {
        pipeline.addLast("codec", new HttpClientCodec());
    } else {
        pipeline.replace("codec", "codec", new HttpClientCodec());
    }
    if (pipeline.get("inflater") == null) {
        pipeline.addLast("inflater", new HttpContentDecompressor());
    } else {
        pipeline.replace("inflater", "inflater", new HttpContentDecompressor());
    }
    if (pipeline.get("chunkedWriter") == null) {
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    } else {
        pipeline.replace("chunkedWriter", "chunkedWriter", new ChunkedWriteHandler());
    }
    //if a connect handler is provided then add it otherwise add the normal response handler
    if (pipeline.get("handler") == null) {
        pipeline.addLast("handler", connectHandler == null ? handler : connectHandler);
    } else {
        pipeline.replace("handler", "handler", connectHandler == null ? handler : connectHandler);
    }
}