use of com.github.tomakehurst.wiremock.common.ProxySettings in project wiremock by wiremock.
the class WireMockServerTests method supportsRecordingProgrammaticallyWithoutHeaderMatching.
// https://github.com/tomakehurst/wiremock/issues/193
@Test
public void supportsRecordingProgrammaticallyWithoutHeaderMatching() {
WireMockServer wireMockServer = new WireMockServer(DYNAMIC_PORT, new SingleRootFileSource(tempDir), false, new ProxySettings("proxy.company.com", DYNAMIC_PORT));
wireMockServer.start();
wireMockServer.enableRecordMappings(new SingleRootFileSource(tempDir + "/mappings"), new SingleRootFileSource(tempDir + "/__files"));
wireMockServer.stubFor(get(urlEqualTo("/something")).willReturn(aResponse().withStatus(200)));
WireMockTestClient client = new WireMockTestClient(wireMockServer.port());
assertThat(client.get("http://localhost:" + wireMockServer.port() + "/something").statusCode(), is(200));
}
use of com.github.tomakehurst.wiremock.common.ProxySettings in project wiremock by wiremock.
the class ProxySettingsTest method parsesHostAndPortCorrectly.
@Test
public void parsesHostAndPortCorrectly() {
ProxySettings settings = ProxySettings.fromString("some.host.org:8888");
assertThat(settings.host(), is("some.host.org"));
assertThat(settings.port(), is(8888));
}
use of com.github.tomakehurst.wiremock.common.ProxySettings in project wiremock by wiremock.
the class HttpClientFactory method createClient.
public static CloseableHttpClient createClient(int maxConnections, int timeoutMilliseconds, ProxySettings proxySettings, KeyStoreSettings trustStoreSettings, boolean trustSelfSignedCertificates, final List<String> trustedHosts, boolean useSystemProperties) {
HttpClientBuilder builder = HttpClientBuilder.create().disableAuthCaching().disableAutomaticRetries().disableCookieManagement().disableRedirectHandling().disableContentCompression().setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create().setMaxConnPerRoute(maxConnections).setMaxConnTotal(maxConnections).setValidateAfterInactivity(// TODO Verify duration
TimeValue.ofSeconds(5)).setConnectionFactory(new ManagedHttpClientConnectionFactory(null, CharCodingConfig.custom().setCharset(UTF_8).build(), null)).build()).setDefaultRequestConfig(RequestConfig.custom().setResponseTimeout(Timeout.ofMilliseconds(timeoutMilliseconds)).build()).setConnectionReuseStrategy((request, response, context) -> false).setKeepAliveStrategy((response, context) -> TimeValue.ZERO_MILLISECONDS);
if (useSystemProperties) {
builder.useSystemProperties();
}
if (proxySettings != NO_PROXY) {
HttpHost proxyHost = new HttpHost(proxySettings.host(), proxySettings.port());
builder.setProxy(proxyHost);
if (!isEmpty(proxySettings.getUsername()) && !isEmpty(proxySettings.getPassword())) {
// TODO Verify
builder.setProxyAuthenticationStrategy(new DefaultAuthenticationStrategy());
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxySettings.host(), proxySettings.port()), new UsernamePasswordCredentials(proxySettings.getUsername(), proxySettings.getPassword().toCharArray()));
builder.setDefaultCredentialsProvider(credentialsProvider);
}
}
final SSLContext sslContext = buildSslContext(trustStoreSettings, trustSelfSignedCertificates, trustedHosts);
LayeredConnectionSocketFactory sslSocketFactory = buildSslConnectionSocketFactory(sslContext);
PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(sslSocketFactory).build();
builder.setConnectionManager(connectionManager);
return builder.build();
}
Aggregations