本文整理汇总了Java中javax.net.ssl.SSLParameters.setApplicationProtocols方法的典型用法代码示例。如果您正苦于以下问题:Java SSLParameters.setApplicationProtocols方法的具体用法?Java SSLParameters.setApplicationProtocols怎么用?Java SSLParameters.setApplicationProtocols使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLParameters
的用法示例。
在下文中一共展示了SSLParameters.setApplicationProtocols方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initSecure
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
final ServerSocket initSecure(int port) throws Exception {
ServerSocketFactory fac;
if (sslContext != null) {
fac = sslContext.getServerSocketFactory();
} else {
fac = SSLServerSocketFactory.getDefault();
}
SSLServerSocket se = (SSLServerSocket) fac.createServerSocket(port);
SSLParameters sslp = se.getSSLParameters();
sslp.setApplicationProtocols(new String[]{"h2"});
se.setSSLParameters(sslp);
se.setEnabledCipherSuites(se.getSupportedCipherSuites());
se.setEnabledProtocols(se.getSupportedProtocols());
// other initialisation here
return se;
}
示例2: getSSLParameters
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
/**
* Returns the SSLParameters in effect for newly accepted connections.
*/
@Override
public synchronized SSLParameters getSSLParameters() {
SSLParameters params = super.getSSLParameters();
// the super implementation does not handle the following parameters
params.setEndpointIdentificationAlgorithm(identificationProtocol);
params.setAlgorithmConstraints(algorithmConstraints);
params.setSNIMatchers(sniMatchers);
params.setUseCipherSuitesOrder(preferLocalCipherSuites);
params.setApplicationProtocols(applicationProtocols);
return params;
}
示例3: test
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
public static void test(boolean async) throws Exception {
System.setProperty("javax.net.ssl.keyStore", KEYSTORE);
System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
System.setProperty("javax.net.ssl.trustStore", KEYSTORE);
System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
SSLServerSocketFactory factory =
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
try (SSLServerSocket ssocket =
(SSLServerSocket) factory.createServerSocket(RANDOM_PORT)) {
// start server
Thread server = new Thread(() -> {
while (true) {
System.out.println("server: ready");
SSLParameters params = ssocket.getSSLParameters();
params.setApplicationProtocols(new String[]{"h2"});
ssocket.setSSLParameters(params);
ready = true;
try (SSLSocket socket = (SSLSocket) ssocket.accept()) {
// just read forever
System.out.println("server: accepted");
while (true) {
socket.getInputStream().read();
}
} catch (IOException e) {
// ignore exceptions on server side
System.out.println("server: exception: " + e);
}
}
});
server.setDaemon(true);
server.start();
// wait for server is ready
do {
Thread.sleep(1000);
} while (!ready);
String uri = "https://localhost:" + ssocket.getLocalPort();
if (async) {
System.out.println(uri + ": Trying to connect asynchronously");
connectAsync(uri);
} else {
System.out.println(uri + ": Trying to connect synchronously");
connect(uri);
}
}
}
示例4: test
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
SSLContext sslContext = (new SimpleSSLContext()).get();
ExecutorService exec = Executors.newCachedThreadPool();
HttpClient client = HttpClient.newBuilder()
.executor(exec)
.sslContext(sslContext)
.sslParameters(new SSLParameters(CIPHER_SUITES))
.version(HTTP_2)
.build();
Http2TestServer httpsServer = null;
try {
SSLContext serverContext = (new SimpleSSLContext()).get();
SSLParameters p = serverContext.getSupportedSSLParameters();
p.setApplicationProtocols(new String[]{"h2"});
httpsServer = new Http2TestServer(true,
0,
exec,
serverContext);
httpsServer.addHandler(new Http2EchoHandler(), "/");
int httpsPort = httpsServer.getAddress().getPort();
String httpsURIString = "https://127.0.0.1:" + httpsPort + "/bar/";
httpsServer.start();
URI uri = URI.create(httpsURIString);
System.err.println("Request to " + uri);
HttpRequest req = HttpRequest.newBuilder(uri)
.POST(fromString(SIMPLE_STRING))
.build();
HttpResponse response;
try {
response = client.send(req, discard(null));
throw new RuntimeException("Unexpected response: " + response);
} catch (IOException e) {
System.err.println("Caught Expected IOException: " + e);
}
System.err.println("DONE");
} finally {
if (httpsServer != null ) { httpsServer.stop(); }
exec.shutdownNow();
}
}