users@grizzly.java.net

Re: SSL how to?

From: Ryan Lubke <ryan.lubke_at_oracle.com>
Date: Sun, 08 Jan 2012 13:00:19 -0800

On 1/6/12 8:23 PM, kevinb wrote:
> This example shows with this GrizzlyWebServer, is there a way to use the
> GrizzlyWebContainerFactory?
>
Once you have the HttpServer instance, you can make the associated
listener(s) secure.

For example:

// -----------------------------------------------------

HttpServer server = ... <Jersey stuff to get the HttpServer instance> ...

server.stop(); // might consider logging a feature request to obtain a
server that isn't started
                      // or expose ssl related methods for creating
secure containers.

SSLContextConfigurator sslContext = new SSLContextConfigurator();
sslContext.setKeyStoreFile("<path to keystore>");
sslContext.setKeyStorePass("<password>");
sslContext.setTrustStoreFile("<path to truststore>");
sslContext.setTrustStorePass("<password>");

for (NetworkListener listener : server.getListeners()) {
     listener.setSecure(true);
     listener.setSSLEngineConfig(
new
SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
}

... <other init stuff> ...

server.start();

// ------------------------------------------------------

Given that Jersey is going to be making changes to support 2.2, now
would be a good time to log a feature
request for creating a secure container without having to try the above.