SSL with Grizzly and Jersey

前端 未结 4 1595
一整个雨季
一整个雨季 2021-02-08 12:30

I\'m trying to get grizzly to use SSL encryption and still work fine with Jersey. I\'ve looked all over the Internet, and I find all kinds of different attempts at SSL with Griz

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-08 13:35

    Sorry to take so long to post this up here. Alexey's answer led me to the working solution, which is a lot like Wolfgang Fahl's code. Here's what I ended up with:

    static HttpServer startSecureServer() throws IOException
    {
        System.out.println("Starting server on port " + ConfigLoader.getHttpsServerPort());
        ResourceConfig rc = new PackagesResourceConfig("com.kinpoint.server.grizzlyresources");
    
        SSLContextConfigurator sslCon = new SSLContextConfigurator();
    
        sslCon.setKeyStoreFile(ConfigLoader.getKeystoreLocation()); // contains server keypair
        sslCon.setKeyStorePass(ConfigLoader.getKeystorePassword());
    
        HttpHandler hand = ContainerFactory.createContainer(HttpHandler.class, rc);
    
        HttpServer secure = GrizzlyServerFactory.createHttpServer(BASE_URI_SECURED, hand, true,
                new SSLEngineConfigurator(sslCon, false, false, false));
    
        return secure;
    }
    

    The second parameter in the SSLEngineConfigurator tells it not to use client mode. That was what was messing me up. Thanks for the help.

提交回复
热议问题