當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。