首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >以编程方式为Jetty 9 embedded配置SSL

以编程方式为Jetty 9 embedded配置SSL
EN

Stack Overflow用户
提问于 2013-01-16 23:44:10
回答 2查看 32.4K关注 0票数 24

我正在使用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();
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14362245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档