I'm trying to update an old RESTful API to allow it to serve https; I don't actually need the added security but I've got clients complaining about mixed context - this is on a deployed desktop application that is just using REST to communicate; not a deployed web app.
This is a jersey 1 implementation and I'm trying to avoid having to upgrade to Jersey 2. The HTTP serving was very easy:
this.server = HttpServerFactory.create(baseUri,
new DefaultResourceConfig(DataPaqResource.class));
So I've looked around and pulled from the javadocs the following to start https or http based on the base uri passed in:
StartWebServer(String baseUri) throws IOException, NoSuchAlgorithmException{
ResourceListeners.addDataPaqResourceListener(this);
if (baseUri.startsWith("https")) {
SSLContext sslContext = SSLContext.getInstance ("SSL");
this.server = (HttpsServer) HttpServerFactory.create(baseUri,
new DefaultResourceConfig(DataPaqResource.class));
((HttpsServer) this.server).setHttpsConfigurator (new HttpsConfigurator(sslContext) {
public void configure (HttpsParameters params) {
SSLContext c = getSSLContext();
// get the default parameters
SSLParameters sslparams = c.getDefaultSSLParameters();
params.setSSLParameters(sslparams);
}
});
}else {
this.server = HttpServerFactory.create(baseUri,
new DefaultResourceConfig(DataPaqResource.class));
}
System.out.println("Started web server on " + baseUri + " imp " +
this.server.getClass().getName());
}
This works fine for http but with https I get:
Error: Client network socket disconnected before secure TLS connection was established
This error is from postman but obviously browsers fail too. Basically I know that the https is configured incorrectly but I'm not sure how to configure it. I don't need the security; I just need to be able to serve https with the minimal amount of configuration.
Any and all help gratefully received!