How to set up SSL on an embedded Jetty?

限于喜欢 提交于 2019-12-04 13:59:04

问题


I've got jetty 7.x embedded. Basically just creating a SelectChannelConnector to listen on port 80 and WebAppContext to deploy a single WAR directory.

I need to add SSL now (all the keystore stuff is done), and I would have guessed to just add an SslSelectChannelConnector, but all the methods are deprecated without any javadocs to explain why, and what to do instead. And the Jetty/SSL docs only show some XML without describing what to do with it.

Can anyone get me the entry point here to setting up SSL an an embedded instance of Jetty? I don't think this will be complicated, I just don't know what class to start with in the current release.


回答1:


A response from the Jetty Users Email Group:

David,

You need to create an instance of SslContextFactory and configure it with your keystore parameters. After that you'll need to pass that instance to the SslSelectChannelConnector's constructor. Recently modified configuration file jetty-ssl.xml shows how it is done in XmlConfiguration, and could be easily translated into code. This will be documented in Jetty Wiki as soon as we get a chance.

-Michael




回答2:


I've been using this and it works just fine for me thus far:

    //Set up SSL keystore
    SslContextFactory sslContextFactory = new SslContextFactory("/etc/mykeystore");
    sslContextFactory.setKeyStorePassword("yourpassword");
    SslSelectChannelConnector selectChannelConnector = new SslSelectChannelConnector(sslContextFactory);
    selectChannelConnector.setPort(4567); //your port


来源:https://stackoverflow.com/questions/6053642/how-to-set-up-ssl-on-an-embedded-jetty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!