以编程方式为 Jetty 9 嵌入式配置 SSL [英] Programmatically Configure SSL for Jetty 9 embedded

查看:36
本文介绍了以编程方式为 Jetty 9 嵌入式配置 SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jetty 版本 9.0.0.M4 并尝试将其配置为接受 SSL 连接.按照以下说明操作:http://www.eclipse.org/jetty/documentation/current/configuring-connectors.html

I'm using jetty version 9.0.0.M4 and am trying to configure it to accept SSL connections. following the instructions in: http://www.eclipse.org/jetty/documentation/current/configuring-connectors.html

我已经设法写出一些有用的东西.然而,我写的代码看起来很丑陋而且不必要地复杂.知道如何正确执行此操作吗?

I've managed to write something that works. However, the code I wrote seems ugly and unnecessarily complex. Any idea how to do this properly?

final Server server = new Server(Config.Server.PORT);

SslContextFactory contextFactory = new SslContextFactory();
contextFactory.setKeyStorePath(Config.Location.KEYSTORE_LOCATION);
contextFactory.setKeyStorePassword("******");
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(contextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_1_1.toString());

HttpConfiguration config = new HttpConfiguration();
config.setSecureScheme("https");
config.setSecurePort(Config.Server.SSL_PORT);
config.setOutputBufferSize(32786);
config.setRequestHeaderSize(8192);
config.setResponseHeaderSize(8192);
HttpConfiguration sslConfiguration = new HttpConfiguration(config);
sslConfiguration.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(sslConfiguration);

ServerConnector connector = new ServerConnector(server, sslConnectionFactory, httpConnectionFactory);
connector.setPort(Config.Server.SSL_PORT);
server.addConnector(connector);

server.start();
server.join();

推荐答案

ServerConnector 应该使用 SslContextFactory.

您在 HttpConfiguration 与设置 SSL 无关.

The rest of the work you are doing in the HttpConfiguration is irrelevant to setting up SSL.

嵌入式码头示例 项目.http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/src/main/java/org/eclipse/码头/嵌入式/LikeJettyXml.java

更清楚(感谢 Erik)

更新:2016 年 6 月

Eclipse Jetty 项目已将其规范存储库移至 github.

The Eclipse Jetty Project has moved its canonical repository to github.

上面的LikeJettyXml.java现在可以在

https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java

这篇关于以编程方式为 Jetty 9 嵌入式配置 SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆