Merge remote-tracking branch 'origin/2.1.x'

This commit is contained in:
Ryan Baxter
2019-06-13 06:56:54 -04:00
4 changed files with 33 additions and 2 deletions

View File

@@ -1435,9 +1435,12 @@ To ensure high availability when you have multiple instances of Config Server de
If you use HTTP basic security on your Config Server, it is currently possible to support per-Config Server auth credentials only if you embed the credentials in each URL you specify under the `spring.cloud.config.uri` property. If you use any other kind of security mechanism, you cannot (currently) support per-Config Server authentication and authorization.
=== Configuring Read Timeouts
=== Configuring Timeouts
If you want to configure read timeout, this can be done by using the property `spring.cloud.config.request-read-timeout`.
If you want to configure timeout thresholds:
* Read timeouts can be configured by using the property `spring.cloud.config.request-read-timeout`.
* Connection timeouts can be configured by using the property `spring.cloud.config.request-connect-timeout`.
=== Security

View File

@@ -114,6 +114,11 @@ public class ConfigClientProperties {
*/
private int requestReadTimeout = (60 * 1000 * 3) + 5000;
/**
* timeout on waiting to connect to the Config Server.
*/
private int requestConnectTimeout = 1000 * 10;
/**
* Flag to indicate whether to send state. Default true.
*/
@@ -227,6 +232,14 @@ public class ConfigClientProperties {
this.requestReadTimeout = requestReadTimeout;
}
public int getRequestConnectTimeout() {
return this.requestConnectTimeout;
}
public void setRequestConnectTimeout(int requestConnectTimeout) {
this.requestConnectTimeout = requestConnectTimeout;
}
public boolean isSendState() {
return this.sendState;
}
@@ -333,6 +346,7 @@ public class ConfigClientProperties {
+ ", username=" + this.username + ", password=" + this.password + ", uri="
+ Arrays.toString(this.uri) + ", discovery=" + this.discovery
+ ", failFast=" + this.failFast + ", token=" + this.token
+ ", requestConnectTimeout=" + this.requestConnectTimeout
+ ", requestReadTimeout=" + this.requestReadTimeout + ", sendState="
+ this.sendState + ", headers=" + this.headers + "]";
}

View File

@@ -257,7 +257,11 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
if (client.getRequestReadTimeout() < 0) {
throw new IllegalStateException("Invalid Value for Read Timeout set.");
}
if (client.getRequestConnectTimeout() < 0) {
throw new IllegalStateException("Invalid Value for Connect Timeout set.");
}
requestFactory.setReadTimeout(client.getRequestReadTimeout());
requestFactory.setConnectTimeout(client.getRequestConnectTimeout());
RestTemplate template = new RestTemplate(requestFactory);
Map<String, String> headers = new HashMap<>(client.getHeaders());
if (headers.containsKey(AUTHORIZATION)) {

View File

@@ -261,6 +261,16 @@ public class ConfigServicePropertySourceLocatorTests {
ReflectionTestUtils.invokeMethod(this.locator, "getSecureRestTemplate", defaults);
}
@Test
public void shouldThrowExceptionWhenNegativeConnectTimeoutSet() {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setRequestConnectTimeout(-1);
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("Invalid Value for Connect Timeout set.");
ReflectionTestUtils.invokeMethod(this.locator, "getSecureRestTemplate", defaults);
}
@Test
public void checkInterceptorHasNoAuthorizationHeaderPresent() {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);