Search in sources :

Example 1 with SSLEngineFactory

use of io.reactivex.netty.pipeline.ssl.SSLEngineFactory in project ribbon by Netflix.

the class LoadBalancingHttpClient method createRxClient.

@Override
protected HttpClient<I, O> createRxClient(Server server) {
    HttpClientBuilder<I, O> clientBuilder;
    if (requestIdProvider != null) {
        clientBuilder = RxContexts.<I, O>newHttpClientBuilder(server.getHost(), server.getPort(), requestIdProvider, RxContexts.DEFAULT_CORRELATOR, pipelineConfigurator);
    } else {
        clientBuilder = RxContexts.<I, O>newHttpClientBuilder(server.getHost(), server.getPort(), RxContexts.DEFAULT_CORRELATOR, pipelineConfigurator);
    }
    Integer connectTimeout = getProperty(IClientConfigKey.Keys.ConnectTimeout, null, DefaultClientConfigImpl.DEFAULT_CONNECT_TIMEOUT);
    Integer readTimeout = getProperty(IClientConfigKey.Keys.ReadTimeout, null, DefaultClientConfigImpl.DEFAULT_READ_TIMEOUT);
    Boolean followRedirect = getProperty(IClientConfigKey.Keys.FollowRedirects, null, null);
    HttpClientConfig.Builder builder = new HttpClientConfig.Builder().readTimeout(readTimeout, TimeUnit.MILLISECONDS);
    if (followRedirect != null) {
        builder.setFollowRedirect(followRedirect);
    }
    clientBuilder.channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout).config(builder.build());
    if (isPoolEnabled()) {
        clientBuilder.withConnectionPoolLimitStrategy(poolStrategy).withIdleConnectionsTimeoutMillis(idleConnectionEvictionMills).withPoolIdleCleanupScheduler(poolCleanerScheduler);
    } else {
        clientBuilder.withNoConnectionPooling();
    }
    if (sslContextFactory != null) {
        try {
            SSLEngineFactory myFactory = new DefaultFactories.SSLContextBasedFactory(sslContextFactory.getSSLContext()) {

                @Override
                public SSLEngine createSSLEngine(ByteBufAllocator allocator) {
                    SSLEngine myEngine = super.createSSLEngine(allocator);
                    myEngine.setUseClientMode(true);
                    return myEngine;
                }
            };
            clientBuilder.withSslEngineFactory(myFactory);
        } catch (ClientSslSocketFactoryException e) {
            throw new RuntimeException(e);
        }
    }
    return clientBuilder.build();
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) ClientSslSocketFactoryException(com.netflix.client.ssl.ClientSslSocketFactoryException) SSLEngine(javax.net.ssl.SSLEngine) URI(java.net.URI) SSLEngineFactory(io.reactivex.netty.pipeline.ssl.SSLEngineFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

ClientSslSocketFactoryException (com.netflix.client.ssl.ClientSslSocketFactoryException)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 SSLEngineFactory (io.reactivex.netty.pipeline.ssl.SSLEngineFactory)1 URI (java.net.URI)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SSLEngine (javax.net.ssl.SSLEngine)1