use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancingHttpClientTests method testDefaultTimeouts.
@Test
public void testDefaultTimeouts() throws Exception {
RequestConfig result = getBuiltRequestConfig(UseDefaults.class, null);
assertThat(result.getConnectTimeout(), is(1000));
assertThat(result.getSocketTimeout(), is(1000));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancingHttpClientTests method testRequestConfigDoNotFollowRedirectsOverrideWithFollowRedirects.
@Test
public void testRequestConfigDoNotFollowRedirectsOverrideWithFollowRedirects() throws Exception {
DefaultClientConfigImpl override = new DefaultClientConfigImpl();
override.set(CommonClientConfigKey.FollowRedirects, true);
override.set(CommonClientConfigKey.IsSecure, false);
RequestConfig result = getBuiltRequestConfig(DoNotFollowRedirects.class, override);
assertThat(result.isRedirectsEnabled(), is(true));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancingHttpClientTests method testRequestConfigUseDefaultsNoOverride.
@Test
public void testRequestConfigUseDefaultsNoOverride() throws Exception {
RequestConfig result = getBuiltRequestConfig(UseDefaults.class, null);
assertThat(result.isRedirectsEnabled(), is(false));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-cloud-netflix by spring-cloud.
the class RetryableRibbonLoadBalancingHttpClient method execute.
@Override
public RibbonApacheHttpResponse execute(final RibbonApacheHttpRequest request, final IClientConfig configOverride) throws Exception {
final RequestConfig.Builder builder = RequestConfig.custom();
IClientConfig config = configOverride != null ? configOverride : this.config;
RibbonProperties ribbon = RibbonProperties.from(config);
builder.setConnectTimeout(ribbon.connectTimeout(this.connectTimeout));
builder.setSocketTimeout(ribbon.readTimeout(this.readTimeout));
builder.setRedirectsEnabled(ribbon.isFollowRedirects(this.followRedirects));
final RequestConfig requestConfig = builder.build();
final LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryFactory.createRetryPolicy(this.getClientName(), this);
RetryCallback<RibbonApacheHttpResponse, Exception> retryCallback = context -> {
// on retries the policy will choose the server and set it in the context
// extract the server and update the request being made
RibbonApacheHttpRequest newRequest = request;
if (context instanceof LoadBalancedRetryContext) {
ServiceInstance service = ((LoadBalancedRetryContext) context).getServiceInstance();
validateServiceInstance(service);
if (service != null) {
// Reconstruct the request URI using the host and port set in the retry context
newRequest = newRequest.withNewUri(UriComponentsBuilder.newInstance().host(service.getHost()).scheme(service.getUri().getScheme()).userInfo(newRequest.getURI().getUserInfo()).port(service.getPort()).path(newRequest.getURI().getPath()).query(newRequest.getURI().getQuery()).fragment(newRequest.getURI().getFragment()).build().encode().toUri());
}
}
newRequest = getSecureRequest(newRequest, configOverride);
HttpUriRequest httpUriRequest = newRequest.toRequest(requestConfig);
final HttpResponse httpResponse = RetryableRibbonLoadBalancingHttpClient.this.delegate.execute(httpUriRequest);
if (retryPolicy.retryableStatusCode(httpResponse.getStatusLine().getStatusCode())) {
throw new HttpClientStatusCodeException(RetryableRibbonLoadBalancingHttpClient.this.clientName, httpResponse, HttpClientUtils.createEntity(httpResponse), httpUriRequest.getURI());
}
return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI());
};
LoadBalancedRecoveryCallback<RibbonApacheHttpResponse, HttpResponse> recoveryCallback = new LoadBalancedRecoveryCallback<RibbonApacheHttpResponse, HttpResponse>() {
@Override
protected RibbonApacheHttpResponse createResponse(HttpResponse response, URI uri) {
return new RibbonApacheHttpResponse(response, uri);
}
};
return this.executeWithRetry(request, retryPolicy, retryCallback, recoveryCallback);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancingHttpClient method execute.
@Override
public RibbonApacheHttpResponse execute(RibbonApacheHttpRequest request, final IClientConfig configOverride) throws Exception {
IClientConfig config = configOverride != null ? configOverride : this.config;
RibbonProperties ribbon = RibbonProperties.from(config);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(ribbon.connectTimeout(this.connectTimeout)).setSocketTimeout(ribbon.readTimeout(this.readTimeout)).setRedirectsEnabled(ribbon.isFollowRedirects(this.followRedirects)).build();
request = getSecureRequest(request, configOverride);
final HttpUriRequest httpUriRequest = request.toRequest(requestConfig);
final HttpResponse httpResponse = this.delegate.execute(httpUriRequest);
return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI());
}
Aggregations