Example usage for com.squareup.okhttp OkHttpClient getSslSocketFactory

List of usage examples for com.squareup.okhttp OkHttpClient getSslSocketFactory

Introduction

In this page you can find the example usage for com.squareup.okhttp OkHttpClient getSslSocketFactory.

Prototype

public SSLSocketFactory getSslSocketFactory() 

Source Link

Usage

From source file:com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest.java

License:Apache License

private void assertThatClientsAreEqual(OkHttpClient clientA, OkHttpClient clientB) {
    assertThat(clientA.getDispatcher()).isEqualTo(clientB.getDispatcher());
    assertThat(clientA.getProxy()).isEqualTo(clientB.getProxy());
    assertThat(clientA.getProtocols()).isEqualTo(clientB.getProtocols());
    assertThat(clientA.getConnectionSpecs()).isEqualTo(clientB.getConnectionSpecs());
    assertThat(clientA.getProxySelector()).isEqualTo(clientB.getProxySelector());
    assertThat(clientA.getCookieHandler()).isEqualTo(clientB.getCookieHandler());
    assertThat(clientA.getCache()).isEqualTo(clientB.getCache());
    assertThat(clientA.getSocketFactory()).isEqualTo(clientB.getSocketFactory());
    assertThat(clientA.getSslSocketFactory()).isEqualTo(clientB.getSslSocketFactory());
    assertThat(clientA.getHostnameVerifier()).isEqualTo(clientB.getHostnameVerifier());
    assertThat(clientA.getCertificatePinner()).isEqualTo(clientB.getCertificatePinner());
    assertThat(clientA.getAuthenticator()).isEqualTo(clientB.getAuthenticator());
    assertThat(clientA.getConnectionPool()).isEqualTo(clientB.getConnectionPool());
    assertThat(clientA.getFollowSslRedirects()).isEqualTo(clientB.getFollowSslRedirects());
    assertThat(clientA.getFollowRedirects()).isEqualTo(clientB.getFollowRedirects());
    assertThat(clientA.getRetryOnConnectionFailure()).isEqualTo(clientB.getRetryOnConnectionFailure());
    assertThat(clientA.getConnectTimeout()).isEqualTo(clientB.getConnectTimeout());
    assertThat(clientA.getReadTimeout()).isEqualTo(clientB.getReadTimeout());
    assertThat(clientA.getWriteTimeout()).isEqualTo(clientB.getWriteTimeout());
}

From source file:keywhiz.client.ClientUtilsTest.java

License:Apache License

@Test
public void testSslOkHttpClientCreation() throws Exception {
    OkHttpClient sslClient = ClientUtils.sslOkHttpClient(config.getDevTrustStore(), ImmutableList.of());

    assertThat(sslClient.getFollowSslRedirects()).isFalse();
    assertThat(sslClient.getSslSocketFactory()).isNotNull();
    assertThat(sslClient.networkInterceptors()).isNotEmpty();

    assertThat(sslClient.getCookieHandler()).isNotNull();
    java.util.List<HttpCookie> cookieList = ((CookieManager) sslClient.getCookieHandler()).getCookieStore()
            .getCookies();//from  w  w  w  .  j av a 2  s.  co m
    assertThat(cookieList).isEmpty();
}

From source file:keywhiz.client.ClientUtilsTest.java

License:Apache License

@Test
public void testSslOkHttpClientCreationWithCookies() throws Exception {
    OkHttpClient sslClient = ClientUtils.sslOkHttpClient(config.getDevTrustStore(), cookieList);

    assertThat(sslClient.getFollowSslRedirects()).isFalse();
    assertThat(sslClient.getCookieHandler()).isNotNull();
    assertThat(sslClient.getSslSocketFactory()).isNotNull();
    assertThat(sslClient.networkInterceptors()).isNotEmpty();

    java.util.List<HttpCookie> cookieList = ((CookieManager) sslClient.getCookieHandler()).getCookieStore()
            .getCookies();/*w  w  w  .ja va 2s. co  m*/
    assertThat(cookieList).contains(xsrfCookie);
    assertThat(cookieList).contains(sessionCookie);
}

From source file:org.sonar.runner.impl.OkHttpClientFactoryTest.java

License:Open Source License

@Test
public void support_tls_1_2_on_java7() {
    when(javaVersion.isJava7()).thenReturn(true);
    OkHttpClient underTest = OkHttpClientFactory.create(javaVersion);

    assertTlsAndClearTextSpecifications(underTest);
    // enable TLS 1.0, 1.1 and 1.2
    assertThat(underTest.getSslSocketFactory()).isNotNull();
}

From source file:org.sonar.runner.impl.OkHttpClientFactoryTest.java

License:Open Source License

@Test
public void support_tls_versions_of_java8() {
    when(javaVersion.isJava7()).thenReturn(false);
    OkHttpClient underTest = OkHttpClientFactory.create(javaVersion);

    assertTlsAndClearTextSpecifications(underTest);
    // do not override the default TLS context provided by java 8
    assertThat(underTest.getSslSocketFactory()).isNull();
}