committed by
Ryan Baxter
parent
4896a22e27
commit
b0433ba689
@@ -116,6 +116,7 @@ public class JGitEnvironmentProperties extends AbstractScmAccessorProperties
|
||||
this.forcePull = forcePull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ public class VaultEnvironmentProperties implements HttpEnvironmentRepositoryProp
|
||||
private Integer port = 8200;
|
||||
/** Vault scheme. Defaults to http. */
|
||||
private String scheme = "http";
|
||||
/** Timeout (in seconds) for obtaining HTTP connection, defaults to 5 seconds. */
|
||||
private int timeout = 5;
|
||||
/** Vault backend. Defaults to secret. */
|
||||
private String backend = "secret";
|
||||
/** The key in vault shared by all applications. Defaults to application. Set to empty to disable. */
|
||||
@@ -46,7 +48,6 @@ public class VaultEnvironmentProperties implements HttpEnvironmentRepositoryProp
|
||||
* over an HTTPS connection.
|
||||
*/
|
||||
private boolean skipSslValidation = false;
|
||||
|
||||
/**
|
||||
* HTTP proxy configuration.
|
||||
*/
|
||||
@@ -133,7 +134,16 @@ public class VaultEnvironmentProperties implements HttpEnvironmentRepositoryProp
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getKvVersion() {
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public int getKvVersion() {
|
||||
return kvVersion;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.cloud.config.server.support;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
@@ -50,6 +51,12 @@ public class HttpClientSupport {
|
||||
httpClientBuilder.setDefaultCredentialsProvider(new ProxyHostCredentialsProvider(httpProxy, httpsProxy));
|
||||
}
|
||||
|
||||
return httpClientBuilder.setSSLContext(sslContextBuilder.build());
|
||||
int timeout = environmentProperties.getTimeout() * 1000;
|
||||
return httpClientBuilder
|
||||
.setSSLContext(sslContextBuilder.build())
|
||||
.setDefaultRequestConfig(RequestConfig.custom()
|
||||
.setSocketTimeout(timeout)
|
||||
.setConnectTimeout(timeout)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,6 @@ public interface HttpEnvironmentRepositoryProperties extends EnvironmentReposito
|
||||
Map<ProxyHostProperties.ProxyForScheme, ProxyHostProperties> getProxy();
|
||||
|
||||
boolean isSkipSslValidation();
|
||||
|
||||
int getTimeout();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.springframework.cloud.config.server.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.cloud.config.server.environment.JGitEnvironmentProperties;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.isA;
|
||||
import static org.junit.internal.matchers.ThrowableCauseMatcher.hasCause;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = HttpClientSupportTest.TestConfiguration.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class HttpClientSupportTest {
|
||||
|
||||
@LocalServerPort
|
||||
private String localServerPort;
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void setsTimeout() throws GeneralSecurityException, IOException {
|
||||
JGitEnvironmentProperties properties = new JGitEnvironmentProperties();
|
||||
properties.setTimeout(1);
|
||||
CloseableHttpClient httpClient = HttpClientSupport.builder(properties).build();
|
||||
|
||||
expectedException.expect(anyOf(isA(SocketTimeoutException.class), hasCause(isA(SocketTimeoutException.class))));
|
||||
|
||||
httpClient.execute(new HttpGet(String.format("http://127.0.0.1:%s/test/endpoint", localServerPort)));
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableWebMvc
|
||||
@EnableAutoConfiguration
|
||||
@RestController
|
||||
static class TestConfiguration {
|
||||
|
||||
@GetMapping("/test/endpoint")
|
||||
public void testEndpoint() throws InterruptedException {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user