本文整理汇总了Java中okhttp3.internal.tls.SslClient类的典型用法代码示例。如果您正苦于以下问题:Java SslClient类的具体用法?Java SslClient怎么用?Java SslClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SslClient类属于okhttp3.internal.tls包,在下文中一共展示了SslClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: connectionsAreNotReusedIfSslSocketFactoryChanges
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Test public void connectionsAreNotReusedIfSslSocketFactoryChanges() throws Exception {
enableHttps();
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
Request request = new Request.Builder()
.url(server.url("/"))
.build();
Response response = client.newCall(request).execute();
response.body().close();
// This client shares a connection pool but has a different SSL socket factory.
SslClient sslClient2 = new SslClient.Builder().build();
OkHttpClient anotherClient = client.newBuilder()
.sslSocketFactory(sslClient2.socketFactory, sslClient2.trustManager)
.build();
// This client fails to connect because the new SSL socket factory refuses.
try {
anotherClient.newCall(request).execute();
fail();
} catch (SSLException expected) {
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ConnectionReuseTest.java
示例2: prepare
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Override public void prepare(Benchmark benchmark) {
super.prepare(benchmark);
client = new OkHttpClient.Builder()
.protocols(benchmark.protocols)
.build();
if (benchmark.tls) {
SslClient sslClient = SslClient.localhost();
SSLSocketFactory socketFactory = sslClient.socketFactory;
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override public boolean verify(String s, SSLSession session) {
return true;
}
};
client = new OkHttpClient.Builder()
.sslSocketFactory(socketFactory, sslClient.trustManager)
.hostnameVerifier(hostnameVerifier)
.build();
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:OkHttp.java
示例3: startServer
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
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;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:Benchmark.java
示例4: prepare
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Override public void prepare(Benchmark benchmark) {
super.prepare(benchmark);
if (benchmark.tls) {
SslClient sslClient = SslClient.localhost();
SSLSocketFactory socketFactory = sslClient.socketFactory;
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override public boolean verify(String s, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:UrlConnection.java
示例5: authWorksWithSsl
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Test public void authWorksWithSsl() throws InterruptedException {
es.useHttps(SslClient.localhost().socketFactory, false);
es.enqueue(new MockResponse()); // let the HEAD request pass, so we can trap the header value
es.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AT_START)); // kill the job
ElasticsearchDependenciesJob.Builder builder = ElasticsearchDependenciesJob.builder()
.username("foo")
.password("bar")
.hosts(es.url("").toString());
// temporarily hack-in self-signed until https://github.com/openzipkin/zipkin/issues/1683
builder.sparkProperties.put("es.net.ssl.cert.allow.self.signed", "true");
ElasticsearchDependenciesJob job = builder.build();
try {
job.run();
} catch (EsHadoopParsingException e) {
// this is ok as we aren't trying to emulate the whole server
}
assertThat(es.takeRequest().getHeader("Authorization"))
.isEqualTo("Basic " + encodeBase64String("foo:bar".getBytes(Util.UTF_8)).trim());
}
开发者ID:openzipkin,项目名称:zipkin-dependencies,代码行数:25,代码来源:ElasticsearchDependenciesJobTest.java
示例6: setUp
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Before
public void setUp()
throws Exception
{
mockWebServer = new MockWebServer();
mockWebServer.useHttps(SslClient.localhost().socketFactory, false);
mockWebServer.start();
client = DigdagClient.builder()
.disableCertValidation(true)
.ssl(true)
.host(mockWebServer.getHostName())
.port(mockWebServer.getPort())
.build();
objectMapper = DigdagClient.objectMapper();
}
开发者ID:treasure-data,项目名称:digdag,代码行数:18,代码来源:DigdagClientTest.java
示例7: prepare
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Override public void prepare(States.GenericState state) {
super.prepare(state);
client = new OkHttpClient.Builder()
.protocols(state.protocols)
.build();
if (state.tls) {
SslClient sslClient = SslClient.localhost();
SSLSocketFactory socketFactory = sslClient.socketFactory;
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override public boolean verify(String s, SSLSession session) {
return true;
}
};
client = new OkHttpClient.Builder()
.sslSocketFactory(socketFactory, sslClient.trustManager)
.hostnameVerifier(hostnameVerifier)
.build();
}
}
开发者ID:apptik,项目名称:jus,代码行数:21,代码来源:OkHttp.java
示例8: startServer
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
private MockWebServer startServer(States.GenericState state) throws IOException {
Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING);
MockWebServer server = new MockWebServer();
if (state.tls) {
SslClient sslClient = SslClient.localhost();
server.useHttps(sslClient.socketFactory, false);
server.setProtocols(state.protocols);
}
final MockResponse response = newResponse(state);
server.setDispatcher(new Dispatcher() {
@Override public MockResponse dispatch(RecordedRequest request) {
return response;
}
});
server.start();
return server;
}
开发者ID:apptik,项目名称:jus,代码行数:21,代码来源:Benchmark.java
示例9: equalsFromTrustManager
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Test public void equalsFromTrustManager() throws Exception {
SslClient client = new SslClient.Builder().build();
X509TrustManager x509TrustManager = client.trustManager;
assertEquals(
CertificateChainCleaner.get(x509TrustManager),
CertificateChainCleaner.get(x509TrustManager));
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:CertificateChainCleanerTest.java
示例10: setUp
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Before public void setUp() throws Exception {
rootCa = new HeldCertificate.Builder()
.serialNumber("1")
.ca(3)
.commonName("root")
.build();
certificate = new HeldCertificate.Builder()
.issuedBy(rootCa)
.serialNumber("2")
.commonName(server.getHostName())
.subjectAlternativeName(server.getHostName())
.subjectAlternativeName("san.com")
.subjectAlternativeName("*.wildcard.com")
.subjectAlternativeName("differentdns.com")
.build();
serverIps = Dns.SYSTEM.lookup(server.getHostName());
dns.set(server.getHostName(), serverIps);
dns.set("san.com", serverIps);
dns.set("nonsan.com", serverIps);
dns.set("www.wildcard.com", serverIps);
dns.set("differentdns.com", Collections.<InetAddress>emptyList());
SslClient sslClient = new SslClient.Builder()
.addTrustedCertificate(rootCa.certificate)
.build();
client = new OkHttpClient.Builder().dns(dns)
.sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
.build();
SslClient serverSslClient = new SslClient.Builder()
.certificateChain(certificate, rootCa)
.build();
server.useHttps(serverSslClient.socketFactory, false);
url = server.url("/robots.txt");
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:ConnectionCoalescingTest.java
示例11: httpsWithIpAddress
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Test public void httpsWithIpAddress() throws Exception {
String localIpAddress = InetAddress.getLoopbackAddress().getHostAddress();
// Create a certificate with an IP address in the subject alt name.
HeldCertificate heldCertificate = new HeldCertificate.Builder()
.commonName("example.com")
.subjectAlternativeName(localIpAddress)
.build();
SslClient sslClient = new SslClient.Builder()
.certificateChain(heldCertificate.keyPair, heldCertificate.certificate)
.addTrustedCertificate(heldCertificate.certificate)
.build();
// Use that certificate on the server and trust it on the client.
server.useHttps(sslClient.socketFactory, false);
client = client.newBuilder()
.sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
.hostnameVerifier(new RecordingHostnameVerifier())
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
.build();
// Make a request.
server.enqueue(new MockResponse());
HttpUrl url = server.url("/").newBuilder()
.host(localIpAddress)
.build();
Request request = new Request.Builder()
.url(url)
.build();
executeSynchronously(request)
.assertCode(200);
// Confirm that the IP address was used in the host header.
RecordedRequest recordedRequest = server.takeRequest();
assertEquals(localIpAddress + ":" + server.getPort(), recordedRequest.getHeader("Host"));
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:CallTest.java
示例12: prepare
import okhttp3.internal.tls.SslClient; //导入依赖的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) {
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);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:NettyHttpClient.java
示例13: prepare
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@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);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:ApacheHttpClient.java
示例14: main
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
public static void main(String... args) throws Exception {
if (args.length != 1 || args[0].startsWith("-")) {
System.out.println("Usage: Http2Server <base directory>");
return;
}
Http2Server server = new Http2Server(new File(args[0]),
SslClient.localhost().sslContext.getSocketFactory());
server.run();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Http2Server.java
示例15: provideDefaultTelemetryClientSettings
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
private TelemetryClientSettings provideDefaultTelemetryClientSettings() {
HttpUrl localUrl = obtainBaseEndpointUrl();
SslClient sslClient = SslClient.localhost();
return new TelemetryClientSettings.Builder()
.baseUrl(localUrl)
.sslSocketFactory(sslClient.socketFactory)
.x509TrustManager(sslClient.trustManager)
.build();
}
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:11,代码来源:MockWebServerTest.java
示例16: checksRequestTimeoutFailure
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Test
public void checksRequestTimeoutFailure() throws Exception {
Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
MapboxTelemetry.applicationContext = mockedContext;
OkHttpClient localOkHttpClientWithShortTimeout = new OkHttpClient.Builder()
.readTimeout(100, TimeUnit.MILLISECONDS)
.build();
HttpUrl localUrl = obtainBaseEndpointUrl();
SslClient sslClient = SslClient.localhost();
TelemetryClientSettings telemetryClientSettings = new TelemetryClientSettings.Builder()
.client(localOkHttpClientWithShortTimeout)
.baseUrl(localUrl)
.sslSocketFactory(sslClient.socketFactory)
.x509TrustManager(sslClient.trustManager)
.build();
TelemetryClient telemetryClient = new TelemetryClient("anyAccessToken", "anyUserAgent", telemetryClientSettings,
mock(Logger.class));
List<Event> theEvent = obtainAnEvent();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<String> bodyRef = new AtomicReference<>();
final AtomicBoolean failureRef = new AtomicBoolean();
Callback aCallback = provideACallback(latch, bodyRef, failureRef);
enqueueMockNoResponse(504);
telemetryClient.sendEvents(theEvent, aCallback);
latch.await();
assertTrue(failureRef.get());
}
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:30,代码来源:TelemetryClientTest.java
示例17: main
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
public static void main(String... args) throws Exception {
if (args.length != 1 || args[0].startsWith("-")) {
System.out.println("Usage: FramedServer <base directory>");
return;
}
Http2Server server = new Http2Server(new File(args[0]),
SslClient.localhost().sslContext.getSocketFactory());
server.run();
}
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:11,代码来源:Http2Server.java
示例18: startMockWebServer
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
public static MockWebServer startMockWebServer(boolean https)
{
MockWebServer server = new MockWebServer();
server.setDispatcher(new NopDispatcher());
if (https) {
server.useHttps(SslClient.localhost().socketFactory, false);
}
try {
server.start(0);
}
catch (IOException e) {
throw Throwables.propagate(e);
}
return server;
}
开发者ID:treasure-data,项目名称:digdag,代码行数:16,代码来源:TestUtils.java
示例19: setUp
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Before
public void setUp()
throws Exception
{
httpMockServer = new MockWebServer();
httpMockServer.start();
httpsMockServer = new MockWebServer();
httpsMockServer.useHttps(SslClient.localhost().socketFactory, false);
httpsMockServer.start();
httpProxy = DefaultHttpProxyServer
.bootstrap()
.withPort(0)
.plusActivityTracker(httpProxyRequestTracker)
.start();
httpProxyUrl = "http://" + httpProxy.getListenAddress().getHostString() + ":" + httpProxy.getListenAddress().getPort();
httpsProxy = DefaultHttpProxyServer
.bootstrap()
.withPort(0)
.plusActivityTracker(httpsProxyRequestTracker)
.withSslEngineSource(new SelfSignedSslEngineSource())
.withAuthenticateSslClients(false)
.start();
httpsProxyUrl = "https://" + httpsProxy.getListenAddress().getHostString() + ":" + httpsProxy.getListenAddress().getPort();
}
开发者ID:treasure-data,项目名称:digdag,代码行数:28,代码来源:CliProxyEnvVarIT.java
示例20: prepare
import okhttp3.internal.tls.SslClient; //导入依赖的package包/类
@Override public void prepare(final States.GenericState state) {
this.concurrencyLevel = state.concurrencyLevel;
this.targetBacklog = state.targetBacklog;
ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {
@Override public void initChannel(SocketChannel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
if (state.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);
}
开发者ID:apptik,项目名称:jus,代码行数:28,代码来源:NettyHttpClient.java
注:本文中的okhttp3.internal.tls.SslClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论