How to set up SSL on an embedded Jetty?

2019-03-21 16:28发布

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.

2条回答
趁早两清
2楼-- · 2019-03-21 16:40

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

查看更多
ゆ 、 Hurt°
3楼-- · 2019-03-21 16:56

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
查看更多
登录 后发表回答