本文整理汇总了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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
};
}
示例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();
}
示例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", "/");
}
示例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();
}