Search in sources :

Example 1 with HttpAsyncClient

use of org.apache.http.nio.client.HttpAsyncClient in project spring-framework by spring-projects.

the class HttpComponentsAsyncClientHttpRequestFactory method createAsyncRequest.

@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
    HttpAsyncClient asyncClient = getHttpAsyncClient();
    startAsyncClient();
    HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
    postProcessHttpRequest(httpRequest);
    HttpContext context = createHttpContext(httpMethod, uri);
    if (context == null) {
        context = HttpClientContext.create();
    }
    // Request configuration not set in the context
    if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
        // Use request configuration given by the user, when available
        RequestConfig config = null;
        if (httpRequest instanceof Configurable) {
            config = ((Configurable) httpRequest).getConfig();
        }
        if (config == null) {
            config = createRequestConfig(asyncClient);
        }
        if (config != null) {
            context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
        }
    }
    return new HttpComponentsAsyncClientHttpRequest(asyncClient, httpRequest, context);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) RequestConfig(org.apache.http.client.config.RequestConfig) HttpContext(org.apache.http.protocol.HttpContext) CloseableHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient) HttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient) Configurable(org.apache.http.client.methods.Configurable)

Aggregations

RequestConfig (org.apache.http.client.config.RequestConfig)1 Configurable (org.apache.http.client.methods.Configurable)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 CloseableHttpAsyncClient (org.apache.http.impl.nio.client.CloseableHttpAsyncClient)1 HttpAsyncClient (org.apache.http.nio.client.HttpAsyncClient)1 HttpContext (org.apache.http.protocol.HttpContext)1