当前位置: 首页>>代码示例>>Java>>正文


Java SslContextBuilder类代码示例

本文整理汇总了Java中com.squareup.okhttp.internal.SslContextBuilder的典型用法代码示例。如果您正苦于以下问题:Java SslContextBuilder类的具体用法?Java SslContextBuilder怎么用?Java SslContextBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SslContextBuilder类属于com.squareup.okhttp.internal包,在下文中一共展示了SslContextBuilder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepare

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:18,代码来源:OkHttp.java

示例2: startServer

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
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;
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:22,代码来源:Benchmark.java

示例3: testConnectionFailsIfSSLConfigurationMissing

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
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);
    }
}
 
开发者ID:abiquo,项目名称:api-java-client,代码行数:17,代码来源:RestClientTest.java

示例4: prepare

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
@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);
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:28,代码来源:NettyHttpClient.java

示例5: prepare

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:15,代码来源:UrlConnection.java

示例6: prepare

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
@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);
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:11,代码来源:ApacheHttpClient.java

示例7: prepare

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
@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;
    }
  };
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:41,代码来源:OkHttpAsync.java

示例8: main

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
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();
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:11,代码来源:SpdyServer.java

示例9: testConnectWithSSL

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
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", "/");
}
 
开发者ID:abiquo,项目名称:api-java-client,代码行数:12,代码来源:RestClientTest.java

示例10: main

import com.squareup.okhttp.internal.SslContextBuilder; //导入依赖的package包/类
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();
}
 
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:12,代码来源:SpdyServer.java


注:本文中的com.squareup.okhttp.internal.SslContextBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。