本文整理汇总了Java中javax.net.ssl.SSLServerSocket.getSupportedProtocols方法的典型用法代码示例。如果您正苦于以下问题:Java SSLServerSocket.getSupportedProtocols方法的具体用法?Java SSLServerSocket.getSupportedProtocols怎么用?Java SSLServerSocket.getSupportedProtocols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLServerSocket
的用法示例。
在下文中一共展示了SSLServerSocket.getSupportedProtocols方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// try {
SSLServerSocketFactory ssf =
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket ss = (SSLServerSocket)ssf.createServerSocket();
String[] protocols = ss.getSupportedProtocols();
for (int i = 0; i < protocols.length; i++) {
// try {
if (protocols[i].equals("SSLv2Hello")) {
continue;
}
SSLContext sslc = SSLContext.getInstance(protocols[i]);
SSLSessionContext sslsc = sslc.getServerSessionContext();
System.out.println("Protocol: " + protocols[i]);
sslsc.setSessionTimeout(Integer.MAX_VALUE);
int newtime = sslsc.getSessionTimeout();
if (newtime != Integer.MAX_VALUE) {
throw new Exception ("Expected timeout: " +
Integer.MAX_VALUE + ", got instead: " +
newtime);
}
// } catch (Exception e) {
// }
}
// } catch (Exception e) {
// System.out.println(e);
// }
System.out.println("Finished");
}
示例2: testSetEnabledProtocolsAffectsGetter
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Test
public void testSetEnabledProtocolsAffectsGetter() throws Exception {
SSLServerSocket socket =
(SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket();
String[] protocols = new String[] {socket.getSupportedProtocols()[0]};
socket.setEnabledProtocols(protocols);
assertEquals(Arrays.asList(protocols), Arrays.asList(socket.getEnabledProtocols()));
}
示例3: testGetSupportedProtocols
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* getSupportedProtocols() method testing.
*/
public void testGetSupportedProtocols() throws Exception {
SSLServerSocket ssocket = createSSLServerSocket();
String[] supported = ssocket.getSupportedProtocols();
assertNotNull(supported);
assertFalse(supported.length == 0);
supported[0] = "NOT_SUPPORTED_PROTOCOL";
supported = ssocket.getSupportedProtocols();
for (int i=0; i<supported.length; i++) {
if ("NOT_SUPPORTED_PROTOCOL".equals(supported[i])) {
fail("Modification of the returned result "
+ "causes the modification of the internal state");
}
}
}
示例4: testGetEnabledProtocols
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* getEnabledProtocols() method testing.
*/
public void testGetEnabledProtocols() throws Exception {
SSLServerSocket ssocket = createSSLServerSocket();
String[] enabled = ssocket.getEnabledProtocols();
assertNotNull(enabled);
String[] supported = ssocket.getSupportedProtocols();
for (int i=0; i<enabled.length; i++) {
//System.out.println("Checking of "+enabled[i]);
found: {
for (int j=0; j<supported.length; j++) {
if (enabled[i].equals(supported[j])) {
break found;
}
}
fail("Enabled protocol does not belong to the set "
+ "of supported protocols: " + enabled[i]);
}
}
ssocket.setEnabledProtocols(supported);
for (int i=0; i<supported.length; i++) {
enabled = new String[supported.length - i];
System.arraycopy(supported, i,
enabled, 0, supported.length-i);
//System.out.println("");
//for (int k=0; k<supported.length - i; k++) {
// System.out.println("---- "+enabled[k]);
//}
ssocket.setEnabledProtocols(enabled);
String[] result = ssocket.getEnabledProtocols();
if (result.length != enabled.length) {
fail("Returned result does not correspond to expected.");
}
for (int k=0; k<result.length; k++) {
found: {
for (int n=0; n<enabled.length; n++) {
if (result[k].equals(enabled[n])) {
break found;
}
}
if (result.length != enabled.length) {
fail("Returned result does not correspond "
+ "to expected.");
}
}
}
}
}
示例5: testSetEnabledProtocols
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* setEnabledProtocols(String[] protocols) method testing.
*/
public void testSetEnabledProtocols() throws Exception {
SSLServerSocket ssocket = createSSLServerSocket();
String[] enabled = ssocket.getEnabledProtocols();
assertNotNull(enabled);
String[] supported = ssocket.getSupportedProtocols();
for (int i=0; i<enabled.length; i++) {
//System.out.println("Checking of "+enabled[i]);
found: {
for (int j=0; j<supported.length; j++) {
if (enabled[i].equals(supported[j])) {
break found;
}
}
fail("Enabled suite does not belong to the set "
+ "of supported cipher suites: " + enabled[i]);
}
}
ssocket.setEnabledProtocols(supported);
ssocket.setEnabledProtocols(enabled);
ssocket.setEnabledProtocols(supported);
String[] more_than_supported = new String[supported.length+1];
for (int i=0; i<supported.length+1; i++) {
more_than_supported[i]
= "NOT_SUPPORTED_PROTOCOL";
System.arraycopy(supported, 0,
more_than_supported, 0, i);
System.arraycopy(supported, i,
more_than_supported, i+1, supported.length-i);
try {
ssocket.setEnabledProtocols(more_than_supported);
fail("Expected IllegalArgumentException was not thrown");
} catch (IllegalArgumentException e) { }
}
enabled = ssocket.getEnabledProtocols();
enabled[0] = "NOT_SUPPORTED_PROTOCOL";
enabled = ssocket.getEnabledProtocols();
for (int i=0; i<enabled.length; i++) {
if ("NOT_SUPPORTED_PROTOCOL".equals(enabled[i])) {
fail("Modification of the returned result "
+ "causes the modification of the internal state");
}
}
}