Search in sources :

Example 1 with VersionInfo

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;
    }
}
Also used : PoolingHttpClientConnectionManagerBuilder(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder) VersionInfo(org.apache.hc.core5.util.VersionInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) HttpClientBuilder(org.apache.hc.client5.http.impl.classic.HttpClientBuilder) MBeanRegistrationException(javax.management.MBeanRegistrationException) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager) MBeanServer(javax.management.MBeanServer)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 HttpClientBuilder (org.apache.hc.client5.http.impl.classic.HttpClientBuilder)1 PoolingHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)1 PoolingHttpClientConnectionManagerBuilder (org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder)1 VersionInfo (org.apache.hc.core5.util.VersionInfo)1