use of org.apache.hc.core5.util.VersionInfo in project LogHub by fbacchella.
the class AbstractHttpSender method configure.
@Override
public boolean configure(Properties properties) {
if (super.configure(properties)) {
if (endPoints.length == 0) {
logger.error("New usable endpoints defined");
return false;
}
// Build HTTP the connection manager
PoolingHttpClientConnectionManagerBuilder cmBuilder = PoolingHttpClientConnectionManagerBuilder.create().setMaxConnTotal(getThreads()).setMaxConnPerRoute(getThreads()).setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).setSoTimeout(timeout, TimeUnit.SECONDS).build()).setValidateAfterInactivity(TimeValue.ofSeconds(1)).setConnPoolPolicy(PoolReusePolicy.FIFO);
if (properties.ssl != null) {
cmBuilder.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(properties.ssl).setTlsVersions(TLS.V_1_3, TLS.V_1_2).build());
}
PoolingHttpClientConnectionManager cm = cmBuilder.build();
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(new Implementation(cm), getObjectName());
} catch (NotCompliantMBeanException | MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
logger.error("jmx configuration failed: " + Helpers.resolveThrowableException(e), e);
return false;
}
// Build the client
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.hc.client5", properties.classloader);
clientBuilder.setUserAgent(String.format("LogHub-HttpClient/%s (Java/%s)", vi.getRelease(), System.getProperty("java.version")));
clientBuilder.setConnectionManager(cm);
clientBuilder.setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(timeout, TimeUnit.SECONDS).setConnectTimeout(timeout, TimeUnit.SECONDS).build());
clientBuilder.disableCookieManagement();
if (credsProvider != null) {
clientBuilder.setDefaultCredentialsProvider(credsProvider);
}
client = clientBuilder.build();
return true;
} else {
return false;
}
}
Aggregations