use of org.apache.hc.client5.http.protocol.HttpClientContext in project feign by OpenFeign.
the class ApacheHttp5Client method execute.
@Override
public Response execute(Request request, Request.Options options) throws IOException {
ClassicHttpRequest httpUriRequest;
try {
httpUriRequest = toClassicHttpRequest(request, options);
} catch (final URISyntaxException e) {
throw new IOException("URL '" + request.url() + "' couldn't be parsed into a URI", e);
}
final HttpHost target = HttpHost.create(URI.create(request.url()));
final HttpClientContext context = configureTimeouts(options);
final ClassicHttpResponse httpResponse = (ClassicHttpResponse) client.execute(target, httpUriRequest, context);
return toFeignResponse(httpResponse, request);
}
use of org.apache.hc.client5.http.protocol.HttpClientContext in project feign by OpenFeign.
the class ApacheHttp5Client method configureTimeouts.
protected HttpClientContext configureTimeouts(Request.Options options) {
final HttpClientContext context = new HttpClientContext();
// per request timeouts
final RequestConfig requestConfig = (client instanceof Configurable ? RequestConfig.copy(((Configurable) client).getConfig()) : RequestConfig.custom()).setConnectTimeout(options.connectTimeout(), options.connectTimeoutUnit()).setResponseTimeout(options.readTimeout(), options.readTimeoutUnit()).build();
context.setRequestConfig(requestConfig);
return context;
}
use of org.apache.hc.client5.http.protocol.HttpClientContext in project feign by OpenFeign.
the class AsyncApacheHttp5Client method configureTimeouts.
protected HttpClientContext configureTimeouts(Request.Options options, HttpClientContext context) {
// per request timeouts
final RequestConfig requestConfig = (client instanceof Configurable ? RequestConfig.copy(((Configurable) client).getConfig()) : RequestConfig.custom()).setConnectTimeout(options.connectTimeout(), options.connectTimeoutUnit()).setResponseTimeout(options.readTimeout(), options.readTimeoutUnit()).build();
context.setRequestConfig(requestConfig);
return context;
}
use of org.apache.hc.client5.http.protocol.HttpClientContext in project feign by OpenFeign.
the class AsyncApacheHttp5Client method execute.
@Override
public CompletableFuture<Response> execute(Request request, Options options, Optional<HttpClientContext> requestContext) {
final SimpleHttpRequest httpUriRequest = toClassicHttpRequest(request, options);
final CompletableFuture<Response> result = new CompletableFuture<>();
final FutureCallback<SimpleHttpResponse> callback = new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(SimpleHttpResponse httpResponse) {
result.complete(toFeignResponse(httpResponse, request));
}
@Override
public void failed(Exception ex) {
result.completeExceptionally(ex);
}
@Override
public void cancelled() {
result.cancel(false);
}
};
client.execute(httpUriRequest, configureTimeouts(options, requestContext.orElseGet(HttpClientContext::new)), callback);
return result;
}
use of org.apache.hc.client5.http.protocol.HttpClientContext in project spring-framework by spring-projects.
the class HttpComponentsClientHttpConnector method connect.
@Override
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
HttpClientContext context = this.contextProvider.apply(method, uri);
if (context.getCookieStore() == null) {
context.setCookieStore(new BasicCookieStore());
}
HttpComponentsClientHttpRequest request = new HttpComponentsClientHttpRequest(method, uri, context, this.dataBufferFactory);
return requestCallback.apply(request).then(Mono.defer(() -> execute(request, context)));
}
Aggregations