Example usage for io.netty.handler.codec.http HttpClientCodec HttpClientCodec

List of usage examples for io.netty.handler.codec.http HttpClientCodec HttpClientCodec

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpClientCodec HttpClientCodec.

Prototype

public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) 

Source Link

Document

Creates a new instance with the specified decoder options.

Usage

From source file:com.king.platform.net.http.netty.ChannelManager.java

License:Apache License

private HttpClientCodec newHttpClientCodec() {
    return new HttpClientCodec(confMap.get(ConfKeys.HTTP_CODEC_MAX_INITIAL_LINE_LENGTH),
            confMap.get(ConfKeys.HTTP_CODEC_MAX_HEADER_SIZE), confMap.get(ConfKeys.HTTP_CODEC_MAX_CHUNK_SIZE));
}

From source file:com.linkedin.r2.transport.http.client.Http2InitializerHandler.java

License:Apache License

/**
 * Sets up HTTP/2 over TCP through protocol upgrade (h2c) pipeline
 *///from  www.  j a  v  a  2s  .  c o  m
private void configureHttpPipeline(ChannelHandlerContext ctx, Request request) throws Exception {
    Http2StreamCodec http2Codec = new Http2StreamCodecBuilder().connection(_connection)
            .maxContentLength(_maxResponseSize).maxHeaderSize(_maxHeaderSize)
            .gracefulShutdownTimeoutMillis(_gracefulShutdownTimeout).streamingTimeout(_streamingTimeout)
            .scheduler(_scheduler).build();
    HttpClientCodec sourceCodec = new HttpClientCodec(MAX_INITIAL_LINE_LENGTH, _maxHeaderSize, _maxChunkSize);
    Http2ClientUpgradeCodec targetCodec = new Http2ClientUpgradeCodec(http2Codec);
    HttpClientUpgradeHandler upgradeCodec = new HttpClientUpgradeHandler(sourceCodec, targetCodec,
            MAX_CLIENT_UPGRADE_CONTENT_LENGTH);
    Http2SchemeHandler schemeHandler = new Http2SchemeHandler(HttpScheme.HTTP.toString());

    String host = request.getURI().getAuthority();
    int port = request.getURI().getPort();
    String path = request.getURI().getPath();

    Http2UpgradeHandler upgradeHandler = new Http2UpgradeHandler(host, port, path);
    Http2StreamResponseHandler responseHandler = new Http2StreamResponseHandler();
    Http2ChannelPoolHandler channelPoolHandler = new Http2ChannelPoolHandler();

    ctx.pipeline().addBefore(ctx.name(), "sourceCodec", sourceCodec);
    ctx.pipeline().addBefore(ctx.name(), "upgradeCodec", upgradeCodec);
    ctx.pipeline().addBefore(ctx.name(), "upgradeHandler", upgradeHandler);
    ctx.pipeline().addBefore(ctx.name(), "schemeHandler", schemeHandler);
    ctx.pipeline().addBefore(ctx.name(), "responseHandler", responseHandler);
    ctx.pipeline().addBefore(ctx.name(), "channelHandler", channelPoolHandler);

    _setupComplete = true;
}

From source file:com.linkedin.r2.transport.http.client.RAPClientPipelineInitializer.java

License:Apache License

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    ch.pipeline().addLast("codec", new HttpClientCodec(4096, _maxHeaderSize, _maxChunkSize));
    ch.pipeline().addLast("rapFullRequestEncoder", new RAPFullRequestEncoder());
    ch.pipeline().addLast("rapEncoder", new RAPRequestEncoder());
    ch.pipeline().addLast("rapDecoder", new RAPResponseDecoder(_maxResponseSize));
    ch.pipeline().addLast("responseHandler", new RAPStreamResponseHandler());
    if (_sslContext != null) {
        ch.pipeline().addLast("sslRequestHandler", new SslRequestHandler(_sslContext, _sslParameters));
    }/*from   w  ww .java  2 s.c om*/
    ch.pipeline().addLast("channelManager", new ChannelPoolStreamHandler());
}

From source file:com.mastfrog.netty.http.client.Initializer.java

License:Open Source License

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (ssl) {/*from w  w  w  .  j  a  v  a2  s  . co  m*/
        SslContext clientContext = context == null
                ? SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build()
                : context;
        pipeline.addLast("ssl", new ExceptionForwardingSslHandler(
                clientContext.newEngine(ByteBufAllocator.DEFAULT, hostPort.host(), hostPort.port())));
    }
    pipeline.addLast("http-codec", new HttpClientCodec(maxInitialLineLength, maxChunkSize, maxChunkSize));
    if (compress) {
        pipeline.addLast("decompressor", new HttpContentDecompressor());
    }
    pipeline.addLast("handler", handler);
}

From source file:com.seagate.kinetic.client.io.provider.nio.http.HttpChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) throws Exception {

    boolean ssl = Boolean.getBoolean("kinetic.io.https");

    ChannelPipeline p = ch.pipeline();/*from   ww  w .j  ava 2  s  .c  om*/

    // Enable HTTPS if necessary.
    if (ssl) {
        SSLEngine engine = SslContextFactory.getClientContext().createSSLEngine();

        engine.setUseClientMode(true);

        p.addLast("ssl", new SslHandler(engine));
    }

    p.addLast("codec", new HttpClientCodec(1024, 4 * 1024, 4 * 1024 * 1024));

    p.addLast("aggregator", new HttpObjectAggregator(4 * 1024 * 1024));

    p.addLast("handler", new HttpMessageServiceHandler(mservice));

    logger.info("http/s channel initialized, use ssl handler=" + ssl);
}

From source file:com.zh.revproxy.SecureProxyInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // Add SSL handler first to encrypt and decrypt everything.
    // In this example, we use a bogus certificate in the server side
    // and accept any invalid certificates in the client side.
    // You will need something more complicated to identify both
    // and server in the real world.

    //      pipeline.addLast(new LoggingHandler(LogLevel.DEBUG));

    if (isSecureBackend) {
        LOGGER.info("Adding the SSL Handler to the pipeline");

        SSLEngine engine = SSLUtil.createClientSSLContext(trustStoreLocation, trustStorePassword)
                .createSSLEngine();/*from   w  ww.j av a2s . c o m*/
        engine.setUseClientMode(true);

        pipeline.addLast("ssl", new SslHandler(engine));
    }

    // needed to forward the decoded request
    // to the backend in encoded form

    pipeline.addLast("encoder", new HttpClientCodec(104857600, 104857600, 104857600));
    pipeline.addLast(new HttpReverseProxyBackendHandler(inbound));
}