Search code examples
javassljerseywebservices-client

Trying to implement SSL on the Jersey client in order to talk to a secure server


I'm following the example atb the end of chapter 3 in Sunil Gulabani's Developing RESTful Web Services with Jersey 2.0" Here's the code:

SSLContext sslContext = null;

   try {
       sslContext = SSLContext.getInstance("SSL");
   } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NullPointerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Client client = ClientBuilder.newBuilder().sslContext(sslContext).build();

The error I get is:

SSLContextImpl is not initialized

I certainly do initialize SSLContext, but SSLContext behaves like a regular class and not like an interface. So, what is SSLContextImpl. Anyone have any ideas?

Thanks, Rob


Solution

  • You have to call SSLContext.init() with appropriate parameters.