private HttpClientBuilder<ByteBuf, ByteBuf> httpClientBuilder() { HttpClientBuilder<ByteBuf, ByteBuf> builder = RxNetty .<ByteBuf, ByteBuf>newHttpClientBuilder(this.serviceEndpoint.getHost(), this.serviceEndpoint.getPort()) .withSslEngineFactory(DefaultFactories.trustAll()).withMaxConnections(connectionPolicy.getMaxPoolSize()) .withIdleConnectionsTimeoutMillis(this.connectionPolicy.getIdleConnectionTimeout() * 1000); ClientConfig config = new ClientConfig.Builder() .readTimeout(connectionPolicy.getRequestTimeout(), TimeUnit.SECONDS).build(); return builder.config(config); }
public ZmonMonitoringSystem(ZmonConfiguration configuration) { HttpClientBuilder<ByteBuf, ByteBuf> builder = RxNetty.newHttpClientBuilder(configuration.getHost(), configuration.getPort()); if (configuration.isSecure()) { builder.withSslEngineFactory(DefaultFactories.trustAll()); } rxNetty = builder.build(); this.configuration = configuration; }
/** * Creates a new hystrix reader. * * @param configuration The configuration to use. * @param cluster The cluster to read from. */ public HystrixReader(Configuration configuration, String cluster) { this.configuration = configuration; this.cluster = cluster; HttpClientBuilder<ByteBuf, ServerSentEvent> builder = RxNetty.newHttpClientBuilder(configuration.getTurbineHost(), configuration.getTurbinePort()); builder.pipelineConfigurator(PipelineConfigurators.clientSseConfigurator()); if (configuration.isSecure()) { builder.withSslEngineFactory(DefaultFactories.trustAll()); } rxNetty = builder.build(); }
@Bean public CompositeHttpClient<ByteBuf, ByteBuf> rxClient() { return new CompositeHttpClientBuilder<ByteBuf, ByteBuf>() .withSslEngineFactory(DefaultFactories.trustAll()).build(); }
/** * Execute an HTTP request. * * @param server Server to send the request to. * @param req Request to execute. * @return Observable with the response of the request. */ private static Observable<HttpClientResponse<ByteBuf>> executeSingle(Server server, HttpClientRequest<ByteBuf> req) { HttpClient.HttpClientConfig config = new HttpClient.HttpClientConfig.Builder() .readTimeout(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS) .userAgent(USER_AGENT) .build(); HttpClientBuilder<ByteBuf, ByteBuf> builder = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(server.host(), server.port()) .pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator()) .config(config) .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS); if (server.isSecure()) { builder.withSslEngineFactory(DefaultFactories.trustAll()); } final HttpClient<ByteBuf, ByteBuf> client = builder.build(); return client.submit(req) .doOnNext(new Action1<HttpClientResponse<ByteBuf>>() { @Override public void call(HttpClientResponse<ByteBuf> res) { LOGGER.debug("Got response: {}", res.getStatus().code()); } }) .doOnError(new Action1<Throwable>() { @Override public void call(Throwable throwable) { LOGGER.info("Error sending metrics: {}/{}", throwable.getClass().getSimpleName(), throwable.getMessage()); } }) .doOnTerminate(new Action0() { @Override public void call() { client.shutdown(); } }); }
@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(); }