Java 类com.squareup.okhttp.internal.SslContextBuilder 实例源码

项目:platform_external_okhttp    文件:OkHttp.java   
@Override public void prepare(Benchmark benchmark) {
  super.prepare(benchmark);
  client = new OkHttpClient();
  client.setProtocols(benchmark.protocols);

  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
      @Override public boolean verify(String s, SSLSession session) {
        return true;
      }
    };
    client.setSslSocketFactory(socketFactory);
    client.setHostnameVerifier(hostnameVerifier);
  }
}
项目:platform_external_okhttp    文件:Benchmark.java   
private MockWebServer startServer() throws IOException {
  Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING);
  MockWebServer server = new MockWebServer();

  if (tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    server.useHttps(sslContext.getSocketFactory(), false);
    server.setNpnEnabled(true);
    server.setNpnProtocols(protocols);
  }

  final MockResponse response = newResponse();
  server.setDispatcher(new Dispatcher() {
    @Override public MockResponse dispatch(RecordedRequest request) {
      return response;
    }
  });

  server.play();
  return server;
}
项目:api-java-client    文件:RestClientTest.java   
public void testConnectionFailsIfSSLConfigurationMissing() throws Exception
{
    server.useHttps(SslContextBuilder.localhost().getSocketFactory(), false);
    server.enqueue(new MockResponse().setResponseCode(204));
    server.start();

    try
    {
        newApiClient().getClient().delete("/");
        fail("SSL handshake should have failed");
    }
    catch (Exception ex)
    {
        assertTrue(ex.getCause() instanceof SSLHandshakeException);
    }
}
项目:platform_external_okhttp    文件:NettyHttpClient.java   
@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) {
        SSLContext sslContext = SslContextBuilder.localhost();
        SSLEngine engine = 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);
}
项目:platform_external_okhttp    文件:UrlConnection.java   
@Override public void prepare(Benchmark benchmark) {
  super.prepare(benchmark);
  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
      @Override public boolean verify(String s, SSLSession session) {
        return true;
      }
    };
    HttpsURLConnectionImpl.setDefaultHostnameVerifier(hostnameVerifier);
    HttpsURLConnectionImpl.setDefaultSSLSocketFactory(socketFactory);
  }
}
项目:platform_external_okhttp    文件:ApacheHttpClient.java   
@Override public void prepare(Benchmark benchmark) {
  super.prepare(benchmark);
  ClientConnectionManager connectionManager = new PoolingClientConnectionManager();
  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    connectionManager.getSchemeRegistry().register(
        new Scheme("https", 443, new SSLSocketFactory(sslContext)));
  }
  client = new DefaultHttpClient(connectionManager);
}
项目:platform_external_okhttp    文件:OkHttpAsync.java   
@Override public void prepare(final Benchmark benchmark) {
  concurrencyLevel = benchmark.concurrencyLevel;
  targetBacklog = benchmark.targetBacklog;

  client = new OkHttpClient();
  client.setProtocols(benchmark.protocols);
  client.setDispatcher(new Dispatcher(new ThreadPoolExecutor(benchmark.concurrencyLevel,
      benchmark.concurrencyLevel, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>())));

  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
      @Override public boolean verify(String s, SSLSession session) {
        return true;
      }
    };
    client.setSslSocketFactory(socketFactory);
    client.setHostnameVerifier(hostnameVerifier);
  }

  receiver = new Response.Receiver() {
    @Override public void onFailure(Failure failure) {
      System.out.println("Failed: " + failure.exception());
    }

    @Override public boolean onResponse(Response response) throws IOException {
      Response.Body body = response.body();
      long total = SynchronousHttpClient.readAllAndClose(body.byteStream());
      long finish = System.nanoTime();
      if (VERBOSE) {
        long start = (Long) response.request().tag();
        System.out.printf("Transferred % 8d bytes in %4d ms%n",
            total, TimeUnit.NANOSECONDS.toMillis(finish - start));
      }
      requestsInFlight.decrementAndGet();
      return true;
    }
  };
}
项目:platform_external_okhttp    文件:SpdyServer.java   
public static void main(String... args) throws Exception {
  if (args.length != 1 || args[0].startsWith("-")) {
    System.out.println("Usage: SpdyServer <base directory>");
    return;
  }

  SpdyServer server = new SpdyServer(new File(args[0]));
  server.useHttps(SslContextBuilder.localhost().getSocketFactory());
  server.run();
}
项目:api-java-client    文件:RestClientTest.java   
public void testConnectWithSSL() throws Exception
{
    server.useHttps(SslContextBuilder.localhost().getSocketFactory(), false);
    server.enqueue(new MockResponse().setResponseCode(204));
    server.start();

    newApiClient(new RelaxedSSLConfig()).getClient().delete("/");

    RecordedRequest request = server.takeRequest();
    assertRequest(request, "DELETE", "/");
}
项目:mirrored-okhttp    文件:SpdyServer.java   
public static void main(String... args) throws Exception {
  if (args.length != 1 || args[0].startsWith("-")) {
    System.out.println("Usage: SpdyServer <base directory>");
    return;
  }

  SpdyServer server = new SpdyServer(new File(args[0]));
  SSLContext sslContext = new SslContextBuilder(InetAddress.getLocalHost().getHostName()).build();
  server.useHttps(sslContext.getSocketFactory());
  server.run();
}