4
所以我想創建一個使用Grizzly/Jersey的REST API服務器,它工作正常,但我無法弄清楚如何啓用http2。關於這個問題的文件幾乎都不存在。這是我有:使用Grizzly的嵌入式Java服務器:你如何啓用http2
private static SSLContext getSSLContext(final String keystore) throws Exception {
SSLContext sslContext = SSLContext.getInstance("TLSv1");
final char[] passphrase = "changeit".toCharArray();
final KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
final KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream stream = Main.class.getResourceAsStream(keystore)) {
ks.load(stream, passphrase);
}
kmf.init(ks, passphrase);
sslContext.init(kmf.getKeyManagers(), null, null);
return sslContext;
}
final ResourceConfig rc = new ResourceConfig().packages("path.to.package");
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, rc, false);
final NetworkListener listener = server.getListeners().iterator().next();
listener.registerAddOn(new Http2AddOn());
listener.setSecure(true);
final SSLEngineConfigurator configurator =
new SSLEngineConfigurator(
getSSLContext("keystore.jks"),
false,
false,
false
);
listener.setSSLEngineConfig(configurator);
而且,據我所知,我在我的pom.xml文件中的所有合適的依賴關係:
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http2</artifactId>
<version>2.3.24</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-npn-bootstrap</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-npn-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
當我測試,捲曲-v服務器--http2 ......,我得到
- ...
- ALPN/NPN,服務器不同意協議
- SSLç onnection使用TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- ...
是否有人知道缺什麼?