Search in sources :

Example 1 with PoolingHttpClientConnectionManagerBuilder

use of org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder in project ksql by confluentinc.

the class DefaultConnectClient method buildHttpClient.

/**
 * Uses defaults from Request.execute(), except with an explicit SSLSocketFactory to pass
 * custom SSL configs. Link to default below:
 * https://github.com/apache/httpcomponents-client/blob/3734aaa038a58c17af638e9fa29019cacb22e82c/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java#L62-L72
 */
private static CloseableHttpClient buildHttpClient(final Optional<SSLContext> sslContext, final boolean verifySslHostname) {
    final PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create();
    sslContext.ifPresent(ctx -> {
        final SSLConnectionSocketFactory socketFactory = verifySslHostname ? new SSLConnectionSocketFactory(ctx) : new SSLConnectionSocketFactory(ctx, (hostname, session) -> true);
        connectionManagerBuilder.setSSLSocketFactory(socketFactory);
    });
    return HttpClientBuilder.create().setConnectionManager(connectionManagerBuilder.setMaxConnPerRoute(100).setMaxConnTotal(200).setValidateAfterInactivity(TimeValue.ofSeconds(10L)).build()).useSystemProperties().evictExpiredConnections().evictIdleConnections(TimeValue.ofMinutes(1L)).build();
}
Also used : HttpClientResponseHandler(org.apache.hc.core5.http.io.HttpClientResponseHandler) SSLContext(javax.net.ssl.SSLContext) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) RetryException(com.github.rholder.retry.RetryException) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Callable(java.util.concurrent.Callable) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Request(org.apache.hc.client5.http.fluent.Request) ConnectorPluginInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorPluginInfo) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) PoolingHttpClientConnectionManagerBuilder(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) URI(java.net.URI) TypeReference(com.fasterxml.jackson.core.type.TypeReference) EntityUtils(org.apache.hc.core5.http.io.entity.EntityUtils) WaitStrategies(com.github.rholder.retry.WaitStrategies) HttpClientBuilder(org.apache.hc.client5.http.impl.classic.HttpClientBuilder) TimeValue(org.apache.hc.core5.util.TimeValue) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Header(org.apache.hc.core5.http.Header) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpHeaders(io.vertx.core.http.HttpHeaders) Collectors(java.util.stream.Collectors) Timeout(org.apache.hc.core5.util.Timeout) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) KsqlServerException(io.confluent.ksql.util.KsqlServerException) List(java.util.List) StopStrategies(com.github.rholder.retry.StopStrategies) Paths(java.nio.file.Paths) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) ContentType(org.apache.hc.core5.http.ContentType) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) HttpEntity(org.apache.hc.core5.http.HttpEntity) CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) HttpStatus(org.apache.hc.core5.http.HttpStatus) Collections(java.util.Collections) PoolingHttpClientConnectionManagerBuilder(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RetryException (com.github.rholder.retry.RetryException)1 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 StopStrategies (com.github.rholder.retry.StopStrategies)1 WaitStrategies (com.github.rholder.retry.WaitStrategies)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KsqlException (io.confluent.ksql.util.KsqlException)1 KsqlServerException (io.confluent.ksql.util.KsqlServerException)1 HttpHeaders (io.vertx.core.http.HttpHeaders)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1