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"));
}
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"));
}
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"));
}
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;
}
}
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;
}
}
Aggregations