use of com.palantir.conjure.java.client.config.ClientConfiguration in project atlasdb by palantir.
the class ClientOptions method create.
public ClientConfiguration create(List<String> endpointUris, Optional<ProxySelector> proxy, TrustContext trustContext) {
ClientConfiguration partialConfig = ClientConfigurations.of(endpointUris, trustContext.sslSocketFactory(), trustContext.x509TrustManager());
ClientConfiguration.Builder builder = ClientConfiguration.builder().from(partialConfig).connectTimeout(connectTimeout()).readTimeout(readTimeout()).backoffSlotSize(backoffSlotSize()).failedUrlCooldown(failedUrlCooldown()).maxNumRetries(maxNumRetries()).enableGcmCipherSuites(true).enableHttp2(true).clientQoS(clientQoS()).serverQoS(serverQoS());
proxy.ifPresent(builder::proxy);
return builder.build();
}
use of com.palantir.conjure.java.client.config.ClientConfiguration in project conjure-java-runtime by palantir.
the class OkHttpClientsTest method clientMadeFromNewBuilderShouldntThrowOnExecute.
@Test
public void clientMadeFromNewBuilderShouldntThrowOnExecute() throws IOException {
server.enqueue(new MockResponse().setBody("foo"));
ClientConfiguration clientConfiguration = createTestConfig(url);
OkHttpClient client = OkHttpClients.create(clientConfiguration, AGENT, hostEventsSink, OkHttpClientsTest.class);
client = client.newBuilder().build();
client.newCall(new Request.Builder().url(url).build()).execute();
}
use of com.palantir.conjure.java.client.config.ClientConfiguration in project conjure-java-runtime by palantir.
the class TestBase method createTestConfig.
protected final ClientConfiguration createTestConfig(String... uri) {
SslConfiguration sslConfig = SslConfiguration.of(Paths.get("src/test/resources/trustStore.jks"));
ClientConfiguration config = ClientConfigurations.of(ImmutableList.copyOf(uri), SslSocketFactories.createSslSocketFactory(sslConfig), SslSocketFactories.createX509TrustManager(sslConfig));
return ClientConfiguration.builder().from(config).userAgent(AGENT).build();
}
use of com.palantir.conjure.java.client.config.ClientConfiguration in project conjure-java-runtime by palantir.
the class JaxRsClientConfigRefreshTest method testConfigRefresh.
@Test
public void testConfigRefresh() throws Exception {
ClientConfiguration config1 = createTestConfig("http://localhost:" + server1.getPort());
ClientConfiguration config2 = createTestConfig("http://localhost:" + server2.getPort());
Refreshable<ClientConfiguration> refreshableConfig = Refreshable.of(config1);
TestService proxy = JaxRsClient.create(TestService.class, UserAgents.tryParse("agent"), new HostMetricsRegistry(), refreshableConfig);
// Call 1
server1.enqueue(new MockResponse().setBody("\"server1\""));
assertThat(proxy.string()).isEqualTo("server1");
assertThat(server1.getRequestCount()).isEqualTo(1);
assertThat(server2.getRequestCount()).isZero();
// Call 2
server1.enqueue(new MockResponse().setBody("\"server1\""));
assertThat(proxy.string()).isEqualTo("server1");
assertThat(server1.getRequestCount()).isEqualTo(2);
assertThat(server2.getRequestCount()).isZero();
// Switch config
refreshableConfig.set(config2);
// Call 3
server2.enqueue(new MockResponse().setBody("\"server2\""));
assertThat(proxy.string()).isEqualTo("server2");
assertThat(server1.getRequestCount()).isEqualTo(2);
assertThat(server2.getRequestCount()).isEqualTo(1);
// Call 4
server2.enqueue(new MockResponse().setBody("\"server2\""));
assertThat(proxy.string()).isEqualTo("server2");
assertThat(server1.getRequestCount()).isEqualTo(2);
assertThat(server2.getRequestCount()).isEqualTo(2);
}
use of com.palantir.conjure.java.client.config.ClientConfiguration in project conjure-java-runtime by palantir.
the class JaxRsClientProxyConfigTest method testDirectVersusProxyConnection.
@Test
public void testDirectVersusProxyConnection() throws Exception {
server.enqueue(new MockResponse().setBody("\"server\""));
proxyServer.enqueue(new MockResponse().setBody("\"proxyServer\""));
TestService directService = JaxRsClient.create(TestService.class, AGENT, new HostMetricsRegistry(), createTestConfig("http://localhost:" + server.getPort()));
ClientConfiguration proxiedConfig = ClientConfiguration.builder().from(createTestConfig("http://localhost:" + server.getPort())).proxy(createProxySelector("localhost", proxyServer.getPort())).build();
TestService proxiedService = JaxRsClient.create(TestService.class, AGENT, new HostMetricsRegistry(), proxiedConfig);
assertThat(directService.string()).isEqualTo("server");
assertThat(proxiedService.string()).isEqualTo("proxyServer");
RecordedRequest proxyRequest = proxyServer.takeRequest();
assertThat(proxyRequest.getHeader("Host")).isEqualTo("localhost:" + server.getPort());
}
Aggregations