本文整理了Java中com.squareup.okhttp.mockwebserver.MockWebServer.useHttps()
方法的一些代码示例,展示了MockWebServer.useHttps()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.useHttps()
方法的具体详情如下:
包路径:com.squareup.okhttp.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:useHttps
[英]Serve requests with HTTPS rather than otherwise.
[中]使用HTTPS服务请求,而不是其他方式。
代码示例来源:origin: apache/jclouds
@Test(expectedExceptions = HttpResponseException.class, expectedExceptionsMessageRegExp = ".*exhausted connection specs.*")
public void testSSLConnectionFailsIfOnlyHttpConfigured() throws Exception {
MockWebServer server = mockWebServer(new MockResponse());
server.useHttps(sslContext.getSocketFactory(), false);
Module httpConfigModule = new ConnectionSpecModule(ConnectionSpec.CLEARTEXT);
PatchApi api = api(PatchApi.class, server.getUrl("/").toString(), httpConfigModule);
try {
api.patchNothing("");
} finally {
closeQuietly(api);
server.shutdown();
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testGetStringRedirect() throws Exception {
MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody(XML2));
redirectTarget.useHttps(sslContext.getSocketFactory(), false);
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location",
redirectTarget.getUrl("/").toString()));
IntegrationTestClient client = client(server.getUrl("/").toString());
try {
String result = client.download("redirect");
assertEquals(result, XML2);
assertEquals(server.getRequestCount(), 1);
assertEquals(redirectTarget.getRequestCount(), 1);
} finally {
closeQuietly(client);
redirectTarget.shutdown();
server.shutdown();
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testRestrictedSSLProtocols() throws Exception {
MockWebServer server = mockWebServer(new MockResponse());
server.useHttps(sslContext.getSocketFactory(), false);
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).tlsVersions(TlsVersion.TLS_1_2)
.build();
PatchApi api = api(PatchApi.class, server.getUrl("/").toString(), new ConnectionSpecModule(spec));
try {
api.patchNothing("");
assertEquals(server.getRequestCount(), 1);
RecordedRequest request = server.takeRequest();
assertEquals(request.getSslProtocol(), "TLSv1.2");
} finally {
closeQuietly(api);
server.shutdown();
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testPatchRedirect() throws Exception {
MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody("fooPATCHREDIRECT"));
redirectTarget.useHttps(sslContext.getSocketFactory(), false);
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location",
redirectTarget.getUrl("/").toString()));
PatchApi api = api(PatchApi.class, server.getUrl("/").toString());
try {
String result = api.patch("", "foo");
assertEquals(result, "fooPATCHREDIRECT");
assertEquals(server.getRequestCount(), 1);
assertEquals(redirectTarget.getRequestCount(), 1);
// Verify that the body was populated after the redirect
RecordedRequest request = server.takeRequest();
assertEquals(request.getMethod(), "PATCH");
assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo");
request = redirectTarget.takeRequest();
assertEquals(request.getMethod(), "PATCH");
assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo");
} finally {
closeQuietly(api);
redirectTarget.shutdown();
server.shutdown();
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testPostRedirect() throws Exception {
MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody("fooPOSTREDIRECT"));
redirectTarget.useHttps(sslContext.getSocketFactory(), false);
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location",
redirectTarget.getUrl("/").toString()));
IntegrationTestClient client = client(server.getUrl("/").toString());
try {
String result = client.post("redirect", "foo");
assertEquals(result, "fooPOSTREDIRECT");
assertEquals(server.getRequestCount(), 1);
assertEquals(redirectTarget.getRequestCount(), 1);
// Verify that the body was populated after the redirect
RecordedRequest request = server.takeRequest();
assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo");
request = redirectTarget.takeRequest();
assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo");
} finally {
closeQuietly(client);
redirectTarget.shutdown();
server.shutdown();
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testPutRedirect() throws Exception {
MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody("fooPUTREDIRECT"));
redirectTarget.useHttps(sslContext.getSocketFactory(), false);
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location",
redirectTarget.getUrl("/").toString()));
IntegrationTestClient client = client(server.getUrl("/").toString());
try {
String result = client.upload("redirect", "foo");
assertEquals(result, "fooPUTREDIRECT");
assertEquals(server.getRequestCount(), 1);
assertEquals(redirectTarget.getRequestCount(), 1);
// Verify that the body was populated after the redirect
RecordedRequest request = server.takeRequest();
assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo");
request = redirectTarget.takeRequest();
assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo");
} finally {
closeQuietly(client);
redirectTarget.shutdown();
server.shutdown();
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testBothProtocolsSucceedIfSSLAndHTTPConfigured() throws Exception {
MockWebServer redirectTarget = mockWebServer(new MockResponse());
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location",
redirectTarget.getUrl("/").toString()));
server.useHttps(sslContext.getSocketFactory(), false);
Module httpConfigModule = new ConnectionSpecModule(ConnectionSpec.CLEARTEXT, ConnectionSpec.MODERN_TLS);
PatchApi api = api(PatchApi.class, server.getUrl("/").toString(), httpConfigModule);
try {
api.patchNothing("");
assertEquals(server.getRequestCount(), 1);
assertEquals(redirectTarget.getRequestCount(), 1);
} finally {
closeQuietly(api);
server.shutdown();
redirectTarget.shutdown();
}
}
内容来源于网络,如有侵权,请联系作者删除!