Commit 6c9fa68d by Ryan Baxter Committed by Spencer Gibb

Translate ribbon.ReadTimeout to apache http client socket timeout. Fixes #1357. (#1358)

parent bc4f5a37
......@@ -16,8 +16,9 @@
package org.springframework.cloud.netflix.ribbon.apache;
import java.net.URI;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ILoadBalancer;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
......@@ -26,9 +27,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient;
import org.springframework.web.util.UriComponentsBuilder;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ILoadBalancer;
import java.net.URI;
/**
* @author Christian Lohmann
......@@ -53,14 +52,14 @@ public class RibbonLoadBalancingHttpClient
if (configOverride != null) {
builder.setConnectTimeout(configOverride.get(
CommonClientConfigKey.ConnectTimeout, this.connectTimeout));
builder.setConnectionRequestTimeout(configOverride.get(
builder.setSocketTimeout(configOverride.get(
CommonClientConfigKey.ReadTimeout, this.readTimeout));
builder.setRedirectsEnabled(configOverride.get(
CommonClientConfigKey.FollowRedirects, this.followRedirects));
}
else {
builder.setConnectTimeout(this.connectTimeout);
builder.setConnectionRequestTimeout(this.readTimeout);
builder.setSocketTimeout(this.readTimeout);
builder.setRedirectsEnabled(this.followRedirects);
}
......
......@@ -67,6 +67,13 @@ public class RibbonLoadBalancingHttpClientTests {
}
@Test
public void testTimeouts() throws Exception {
RequestConfig result = getBuiltRequestConfig(Timeouts.class, null);
assertThat(result.getConnectTimeout(), is(60000));
assertThat(result.getSocketTimeout(), is (50000));
}
@Test
public void testRequestConfigDoNotFollowRedirectsOverrideWithFollowRedirects()
throws Exception {
......@@ -117,6 +124,17 @@ public class RibbonLoadBalancingHttpClientTests {
}
}
@Configuration
protected static class Timeouts {
@Bean
public IClientConfig clientConfig() {
DefaultClientConfigImpl config = new DefaultClientConfigImpl();
config.set(CommonClientConfigKey.ConnectTimeout, 60000);
config.set(CommonClientConfigKey.ReadTimeout, 50000);
return config;
}
}
private RequestConfig getBuiltRequestConfig(Class<?> defaultConfigurationClass,
IClientConfig configOverride) throws Exception {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment