【发布时间】:2013-01-16 15:44:09
【问题描述】:
我正在使用 jetty 版本 9.0.0.M4 并尝试将其配置为接受 SSL 连接。 按照以下说明: http://www.eclipse.org/jetty/documentation/current/configuring-connectors.html
我设法写了一些有用的东西。 但是,我编写的代码看起来很丑陋而且不必要地复杂。 知道如何正确执行此操作吗?
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();
【问题讨论】:
-
在这个问题上做得很好