Search in sources :

Example 6 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project mapbox-events-android by mapbox.

the class MockWebServerTest method provideDefaultTelemetryClientSettings.

private TelemetryClientSettings provideDefaultTelemetryClientSettings() {
    HttpUrl localUrl = obtainBaseEndpointUrl();
    SslClient sslClient = SslClient.localhost();
    return new TelemetryClientSettings.Builder().baseUrl(localUrl).sslSocketFactory(sslClient.socketFactory).x509TrustManager(sslClient.trustManager).hostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    }).build();
}
Also used : SslClient(okhttp3.mockwebserver.internal.tls.SslClient) SSLSession(javax.net.ssl.SSLSession) HttpUrl(okhttp3.HttpUrl) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 7 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project keywhiz by square.

the class ClientUtilsTest method testSslOkHttpClientCreation.

@Test
public void testSslOkHttpClientCreation() throws Exception {
    OkHttpClient sslClient = ClientUtils.sslOkHttpClient(config.getDevTrustStore(), ImmutableList.of());
    assertThat(sslClient.followSslRedirects()).isFalse();
    assertThat(sslClient.sslSocketFactory()).isNotNull();
    assertThat(sslClient.cookieJar()).isNotNull();
    java.util.List<HttpCookie> cookieList = ClientUtils.getCookieManager().getCookieStore().getCookies();
    assertThat(cookieList).isEmpty();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpCookie(java.net.HttpCookie) Test(org.junit.Test)

Example 8 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project okhttp by square.

the class ApacheHttpClient method prepare.

@Override
public void prepare(Benchmark benchmark) {
    super.prepare(benchmark);
    ClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    if (benchmark.tls) {
        SslClient sslClient = SslClient.localhost();
        connectionManager.getSchemeRegistry().register(new Scheme("https", 443, new SSLSocketFactory(sslClient.sslContext)));
    }
    client = new DefaultHttpClient(connectionManager);
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) SslClient(okhttp3.internal.tls.SslClient) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 9 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project okhttp by square.

the class Benchmark method startServer.

private MockWebServer startServer() throws IOException {
    Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING);
    MockWebServer server = new MockWebServer();
    if (tls) {
        SslClient sslClient = SslClient.localhost();
        server.useHttps(sslClient.socketFactory, false);
        server.setProtocols(protocols);
    }
    final MockResponse response = newResponse();
    server.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) {
            return response;
        }
    });
    server.start();
    return server;
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SslClient(okhttp3.internal.tls.SslClient) MockWebServer(okhttp3.mockwebserver.MockWebServer) Dispatcher(okhttp3.mockwebserver.Dispatcher)

Example 10 with SslClient

use of okhttp3.mockwebserver.internal.tls.SslClient in project okhttp by square.

the class NettyHttpClient method prepare.

@Override
public void prepare(final Benchmark benchmark) {
    this.concurrencyLevel = benchmark.concurrencyLevel;
    this.targetBacklog = benchmark.targetBacklog;
    ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel channel) throws Exception {
            ChannelPipeline pipeline = channel.pipeline();
            if (benchmark.tls) {
                SslClient sslClient = SslClient.localhost();
                SSLEngine engine = sslClient.sslContext.createSSLEngine();
                engine.setUseClientMode(true);
                pipeline.addLast("ssl", new SslHandler(engine));
            }
            pipeline.addLast("codec", new HttpClientCodec());
            pipeline.addLast("inflater", new HttpContentDecompressor());
            pipeline.addLast("handler", new HttpChannel(channel));
        }
    };
    bootstrap = new Bootstrap();
    bootstrap.group(new NioEventLoopGroup(concurrencyLevel)).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).channel(NioSocketChannel.class).handler(channelInitializer);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) SSLEngine(javax.net.ssl.SSLEngine) SslClient(okhttp3.internal.tls.SslClient) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Bootstrap(io.netty.bootstrap.Bootstrap) ChannelInitializer(io.netty.channel.ChannelInitializer) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

SslClient (okhttp3.internal.tls.SslClient)10 Test (org.junit.Test)6 HostnameVerifier (javax.net.ssl.HostnameVerifier)5 SSLSession (javax.net.ssl.SSLSession)5 OkHttpClient (okhttp3.OkHttpClient)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 IOException (java.io.IOException)2 HttpCookie (java.net.HttpCookie)2 Callback (okhttp3.Callback)2 HttpUrl (okhttp3.HttpUrl)2 HeldCertificate (okhttp3.internal.tls.HeldCertificate)2 MockWebServer (okhttp3.mockwebserver.MockWebServer)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 SslClient (okhttp3.mockwebserver.internal.tls.SslClient)2 Context (android.content.Context)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1