Search in sources :

Example 1 with HttpComponentsAsyncClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method restartWithKeepAlive.

@Test
public void restartWithKeepAlive() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    HttpComponentsAsyncClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory();
    ListenableFuture<ClientHttpResponse> response1 = clientHttpRequestFactory.createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET).executeAsync();
    assertThat(response1.get(10, TimeUnit.SECONDS).getRawStatusCode()).isEqualTo(200);
    this.webServer.stop();
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    ListenableFuture<ClientHttpResponse> response2 = clientHttpRequestFactory.createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET).executeAsync();
    assertThat(response2.get(10, TimeUnit.SECONDS).getRawStatusCode()).isEqualTo(200);
    clientHttpRequestFactory.destroy();
}
Also used : URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) HttpComponentsAsyncClientHttpRequestFactory(org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory) Test(org.junit.Test)

Example 2 with HttpComponentsAsyncClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory in project brave by openzipkin.

the class ITTracingAsyncClientHttpRequestInterceptor method configureClient.

AsyncClientHttpRequestFactory configureClient(AsyncClientHttpRequestInterceptor interceptor) {
    HttpComponentsAsyncClientHttpRequestFactory factory = new HttpComponentsAsyncClientHttpRequestFactory();
    factory.setReadTimeout(1000);
    factory.setConnectTimeout(1000);
    this.interceptor = interceptor;
    return factory;
}
Also used : HttpComponentsAsyncClientHttpRequestFactory(org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory)

Example 3 with HttpComponentsAsyncClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory in project instrumentation-java by census-instrumentation.

the class ApplicationAutoConfiguration method getAsyncClientHttpRequestFactory.

/**
 * Factory for AsyncClientHttpRequest.
 *
 * @return AsyncClientHttpRequestFactory
 */
@Bean
public AsyncClientHttpRequestFactory getAsyncClientHttpRequestFactory() {
    int timeout = 5000;
    HttpComponentsAsyncClientHttpRequestFactory asyncClientHttpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory();
    asyncClientHttpRequestFactory.setConnectTimeout(timeout);
    return asyncClientHttpRequestFactory;
}
Also used : HttpComponentsAsyncClientHttpRequestFactory(org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory) Bean(org.springframework.context.annotation.Bean)

Aggregations

HttpComponentsAsyncClientHttpRequestFactory (org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory)3 URI (java.net.URI)1 Test (org.junit.Test)1 Bean (org.springframework.context.annotation.Bean)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1