本文整理匯總了Java中javax.net.ssl.HttpsURLConnection.getPeerPrincipal方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpsURLConnection.getPeerPrincipal方法的具體用法?Java HttpsURLConnection.getPeerPrincipal怎麽用?Java HttpsURLConnection.getPeerPrincipal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.net.ssl.HttpsURLConnection
的用法示例。
在下文中一共展示了HttpsURLConnection.getPeerPrincipal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: secureResponseCaching
import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
@Test public void secureResponseCaching() throws IOException {
assumeFalse(getPlatform().equals("jdk9"));
server.useHttps(sslClient.socketFactory, false);
server.enqueue(new MockResponse()
.addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
.addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
.setBody("ABC"));
HttpsURLConnection c1 = (HttpsURLConnection) openConnection(server.url("/").url());
c1.setSSLSocketFactory(sslClient.socketFactory);
c1.setHostnameVerifier(hostnameVerifier);
assertEquals("ABC", readAscii(c1));
// OpenJDK 6 fails on this line, complaining that the connection isn't open yet
String suite = c1.getCipherSuite();
List<Certificate> localCerts = toListOrNull(c1.getLocalCertificates());
List<Certificate> serverCerts = toListOrNull(c1.getServerCertificates());
Principal peerPrincipal = c1.getPeerPrincipal();
Principal localPrincipal = c1.getLocalPrincipal();
HttpsURLConnection c2 = (HttpsURLConnection) openConnection(server.url("/").url()); // cached!
c2.setSSLSocketFactory(sslClient.socketFactory);
c2.setHostnameVerifier(hostnameVerifier);
assertEquals("ABC", readAscii(c2));
assertEquals(suite, c2.getCipherSuite());
assertEquals(localCerts, toListOrNull(c2.getLocalCertificates()));
assertEquals(serverCerts, toListOrNull(c2.getServerCertificates()));
assertEquals(peerPrincipal, c2.getPeerPrincipal());
assertEquals(localPrincipal, c2.getLocalPrincipal());
}
示例2: secureResponseCaching
import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
@Test public void secureResponseCaching() throws IOException {
assumeFalse(getPlatform().equals("jdk9"));
server.useHttps(sslClient.socketFactory, false);
server.enqueue(new MockResponse().addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
.addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
.setBody("ABC"));
HttpsURLConnection c1 = (HttpsURLConnection) urlFactory.open(server.url("/").url());
c1.setSSLSocketFactory(sslClient.socketFactory);
c1.setHostnameVerifier(NULL_HOSTNAME_VERIFIER);
assertEquals("ABC", readAscii(c1));
// OpenJDK 6 fails on this line, complaining that the connection isn't open yet
String suite = c1.getCipherSuite();
List<Certificate> localCerts = toListOrNull(c1.getLocalCertificates());
List<Certificate> serverCerts = toListOrNull(c1.getServerCertificates());
Principal peerPrincipal = c1.getPeerPrincipal();
Principal localPrincipal = c1.getLocalPrincipal();
HttpsURLConnection c2 = (HttpsURLConnection) urlFactory.open(server.url("/").url()); // cached!
c2.setSSLSocketFactory(sslClient.socketFactory);
c2.setHostnameVerifier(NULL_HOSTNAME_VERIFIER);
assertEquals("ABC", readAscii(c2));
assertEquals(2, cache.requestCount());
assertEquals(1, cache.networkCount());
assertEquals(1, cache.hitCount());
assertEquals(suite, c2.getCipherSuite());
assertEquals(localCerts, toListOrNull(c2.getLocalCertificates()));
assertEquals(serverCerts, toListOrNull(c2.getServerCertificates()));
assertEquals(peerPrincipal, c2.getPeerPrincipal());
assertEquals(localPrincipal, c2.getLocalPrincipal());
}