Search in sources :

Example 1 with org.apache.hc.client5.http.classic.methods

use of org.apache.hc.client5.http.classic.methods in project metrics by dropwizard.

the class HttpClientMetricNameStrategiesTest method hostAndMethodWithoutNameInWrappedRequest.

@Test
public void hostAndMethodWithoutNameInWrappedRequest() throws URISyntaxException {
    HttpRequest request = rewriteRequestURI(new HttpPost("http://my.host.com/whatever"));
    assertThat(HOST_AND_METHOD.getNameFor(null, request), is("org.apache.hc.client5.http.classic.HttpClient.my.host.com.post-requests"));
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) HttpPost(org.apache.hc.client5.http.classic.methods.HttpPost) Test(org.junit.Test)

Example 2 with org.apache.hc.client5.http.classic.methods

use of org.apache.hc.client5.http.classic.methods in project metrics by dropwizard.

the class HttpClientMetricNameStrategiesTest method querylessUrlAndMethodWithNameInWrappedRequest.

@Test
public void querylessUrlAndMethodWithNameInWrappedRequest() throws URISyntaxException {
    HttpRequest request = rewriteRequestURI(new HttpPut("https://thing.com:8090/my/path?ignore=this&and=this"));
    assertThat(QUERYLESS_URL_AND_METHOD.getNameFor("some-service", request), is("org.apache.hc.client5.http.classic.HttpClient.some-service.https://thing.com:8090/my/path.put-requests"));
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) HttpPut(org.apache.hc.client5.http.classic.methods.HttpPut) Test(org.junit.Test)

Example 3 with org.apache.hc.client5.http.classic.methods

use of org.apache.hc.client5.http.classic.methods in project metrics by dropwizard.

the class HttpClientMetricNameStrategiesTest method hostAndMethodWithNameInWrappedRequest.

@Test
public void hostAndMethodWithNameInWrappedRequest() throws URISyntaxException {
    HttpRequest request = rewriteRequestURI(new HttpPost("http://my.host.com/whatever"));
    assertThat(HOST_AND_METHOD.getNameFor("some-service", request), is("org.apache.hc.client5.http.classic.HttpClient.some-service.my.host.com.post-requests"));
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) HttpPost(org.apache.hc.client5.http.classic.methods.HttpPost) Test(org.junit.Test)

Example 4 with org.apache.hc.client5.http.classic.methods

use of org.apache.hc.client5.http.classic.methods 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)

Example 5 with org.apache.hc.client5.http.classic.methods

use of org.apache.hc.client5.http.classic.methods in project invesdwin-util by invesdwin.

the class URIsConnectApacheSync method lastModified.

@Override
public long lastModified() {
    try (CloseableHttpResponse response = openConnection(HEAD)) {
        if (!URIs.isSuccessful(response.getCode())) {
            return -1;
        }
        final String lastModifiedStr = response.getFirstHeader(HttpHeaders.LAST_MODIFIED).getValue();
        if (lastModifiedStr == null) {
            return -1;
        }
        final Date lastModified = org.apache.hc.client5.http.utils.DateUtils.parseDate(lastModifiedStr);
        if (lastModified == null) {
            return -1;
        } else {
            return lastModified.getTime();
        }
    } catch (final Throwable e) {
        return -1;
    }
}
Also used : CloseableHttpResponse(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse) Date(java.util.Date)

Aggregations

HttpRequest (org.apache.hc.core5.http.HttpRequest)3 Test (org.junit.Test)3 Date (java.util.Date)2 HttpPost (org.apache.hc.client5.http.classic.methods.HttpPost)2 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 SimpleHttpResponse (org.apache.hc.client5.http.async.methods.SimpleHttpResponse)1 HttpPut (org.apache.hc.client5.http.classic.methods.HttpPut)1 CloseableHttpResponse (org.apache.hc.client5.http.impl.classic.CloseableHttpResponse)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