Search in sources :

Example 1 with HttpRequest

use of org.apache.hc.core5.http.HttpRequest 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 HttpRequest

use of org.apache.hc.core5.http.HttpRequest 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 HttpRequest

use of org.apache.hc.core5.http.HttpRequest 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 HttpRequest

use of org.apache.hc.core5.http.HttpRequest in project cxf by apache.

the class AsyncHTTPConduitFactory method setupNIOClient.

public synchronized void setupNIOClient(HTTPClientPolicy clientPolicy) {
    if (client != null) {
        return;
    }
    final IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(ioThreadCount).setSelectInterval(TimeValue.ofMilliseconds(selectInterval)).setSoLinger(TimeValue.ofMilliseconds(soLinger)).setSoTimeout(Timeout.ofMilliseconds(soTimeout)).setSoKeepAlive(soKeepalive).setTcpNoDelay(tcpNoDelay).build();
    final Registry<TlsStrategy> tlsStrategy = RegistryBuilder.<TlsStrategy>create().register("https", DefaultClientTlsStrategy.getSystemDefault()).build();
    connectionManager = new PoolingAsyncClientConnectionManager(tlsStrategy, PoolConcurrencyPolicy.STRICT, PoolReusePolicy.LIFO, TimeValue.ofMilliseconds(connectionTTL), DefaultSchemePortResolver.INSTANCE, SystemDefaultDnsResolver.INSTANCE);
    connectionManager.setDefaultMaxPerRoute(maxPerRoute);
    connectionManager.setMaxTotal(maxConnections);
    final RedirectStrategy redirectStrategy = new RedirectStrategy() {

        public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
            return false;
        }

        public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
            return null;
        }
    };
    final HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom().setConnectionManager(connectionManager).setRedirectStrategy(redirectStrategy).setDefaultCookieStore(new BasicCookieStore() {

        private static final long serialVersionUID = 1L;

        public void addCookie(Cookie cookie) {
        }
    });
    adaptClientBuilder(httpAsyncClientBuilder);
    client = httpAsyncClientBuilder.setIOReactorConfig(config).build();
    // Start the client thread
    client.start();
    // Always start the idle checker thread to validate pending requests and
    // use the ConnectionMaxIdle to close the idle connection
    new CloseIdleConnectionThread(connectionManager, client).start();
}
Also used : TlsStrategy(org.apache.hc.core5.http.nio.ssl.TlsStrategy) DefaultClientTlsStrategy(org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy) HttpRequest(org.apache.hc.core5.http.HttpRequest) Cookie(org.apache.hc.client5.http.cookie.Cookie) HttpContext(org.apache.hc.core5.http.protocol.HttpContext) HttpResponse(org.apache.hc.core5.http.HttpResponse) HttpAsyncClientBuilder(org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder) IOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig) BasicCookieStore(org.apache.hc.client5.http.cookie.BasicCookieStore) PoolingAsyncClientConnectionManager(org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager) RedirectStrategy(org.apache.hc.client5.http.protocol.RedirectStrategy)

Example 5 with HttpRequest

use of org.apache.hc.core5.http.HttpRequest in project metrics by dropwizard.

the class HttpClientMetricNameStrategiesTest method rewriteRequestURI.

private static HttpRequest rewriteRequestURI(HttpRequest request) throws URISyntaxException {
    HttpRequestWrapper wrapper = new HttpRequestWrapper(request);
    URI uri = URIUtils.rewriteURI(wrapper.getUri(), null, true);
    wrapper.setUri(uri);
    return wrapper;
}
Also used : HttpRequestWrapper(org.apache.hc.core5.http.message.HttpRequestWrapper) URI(java.net.URI)

Aggregations

HttpRequest (org.apache.hc.core5.http.HttpRequest)4 Test (org.junit.Test)3 HttpPost (org.apache.hc.client5.http.classic.methods.HttpPost)2 URI (java.net.URI)1 HttpPut (org.apache.hc.client5.http.classic.methods.HttpPut)1 BasicCookieStore (org.apache.hc.client5.http.cookie.BasicCookieStore)1 Cookie (org.apache.hc.client5.http.cookie.Cookie)1 HttpAsyncClientBuilder (org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder)1 PoolingAsyncClientConnectionManager (org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager)1 RedirectStrategy (org.apache.hc.client5.http.protocol.RedirectStrategy)1 DefaultClientTlsStrategy (org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy)1 HttpResponse (org.apache.hc.core5.http.HttpResponse)1 HttpRequestWrapper (org.apache.hc.core5.http.message.HttpRequestWrapper)1 TlsStrategy (org.apache.hc.core5.http.nio.ssl.TlsStrategy)1 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)1 IOReactorConfig (org.apache.hc.core5.reactor.IOReactorConfig)1