Search in sources :

Example 1 with ClientConfiguration

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();
}
Also used : ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration)

Example 2 with ClientConfiguration

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();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) OkHttpClient(okhttp3.OkHttpClient) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) Test(org.junit.Test)

Example 3 with ClientConfiguration

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();
}
Also used : SslConfiguration(com.palantir.conjure.java.api.config.ssl.SslConfiguration) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration)

Example 4 with ClientConfiguration

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) HostMetricsRegistry(com.palantir.conjure.java.okhttp.HostMetricsRegistry) Test(org.junit.Test)

Example 5 with ClientConfiguration

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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HostMetricsRegistry(com.palantir.conjure.java.okhttp.HostMetricsRegistry) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)40 Channel (com.palantir.dialogue.Channel)16 Test (org.junit.jupiter.api.Test)14 Response (com.palantir.dialogue.Response)13 MockResponse (okhttp3.mockwebserver.MockResponse)11 Test (org.junit.Test)11 IOException (java.io.IOException)9 TestEndpoint (com.palantir.dialogue.TestEndpoint)8 Undertow (io.undertow.Undertow)8 Duration (java.time.Duration)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 SslSocketFactories (com.palantir.conjure.java.config.ssl.SslSocketFactories)6 HostMetricsRegistry (com.palantir.conjure.java.okhttp.HostMetricsRegistry)6 Request (com.palantir.dialogue.Request)6 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)6 OutputStream (java.io.OutputStream)6 SSLContext (javax.net.ssl.SSLContext)6 ResponseCodeHandler (io.undertow.server.handlers.ResponseCodeHandler)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5