开发者

How to set up SSL on an embedded Jetty?

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.


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜