InetSocketAddress address = new InetSocketAddress ( getProxyCallbackURLPrefix().getPort() );
// initialise the HTTPS server
HttpsServer httpsServer = HttpsServer.create ( address, 0 );
SSLContext sslContext = SSLContext.getInstance ( "TLS" );
// initialise the keystore
char[] password = "changeit".toCharArray ();
KeyStore ks = KeyStore.getInstance ( "JKS" );
File base = new File(System.getProperty("user.home"), ".geoserver");
File keystore = new File(base,"keystore.jks");
FileInputStream fis = new FileInputStream ( keystore );
ks.load ( fis, password );
// setup the key manager factory
KeyManagerFactory kmf = KeyManagerFactory.getInstance ( KeyManagerFactory.getDefaultAlgorithm() );
kmf.init ( ks, password );
// setup the trust manager factory
//TrustManagerFactory tmf = TrustManagerFactory.getInstance ( TrustManagerFactory.getDefaultAlgorithm() );
//tmf.init ( ks );
// setup the HTTPS context and parameters
sslContext.init ( kmf.getKeyManagers (), new TrustManager[]{trustManager}, null );
httpsServer.setHttpsConfigurator( new HttpsConfigurator( sslContext )
{
public void configure ( HttpsParameters params )
{
try
{
// initialise the SSL context
SSLContext c = SSLContext.getDefault ();
SSLEngine engine = c.createSSLEngine ();
params.setNeedClientAuth ( false );
params.setCipherSuites ( engine.getEnabledCipherSuites () );
params.setProtocols ( engine.getEnabledProtocols () );
// get the default parameters
SSLParameters defaultSSLParameters = c.getDefaultSSLParameters ();
params.setSSLParameters ( defaultSSLParameters );
}
catch ( Exception ex )
{
throw new RuntimeException(ex);
}
}
} );
httpsServer.createContext("/test", new HttpHandler() {
@Override
public void handle(HttpExchange t) throws IOException {
LOGGER.info("https server working");
t.getRequestBody().close();
t.sendResponseHeaders(200, 0);
t.getResponseBody().close();
}
});
httpsServer.setExecutor(null); // creates a default executor
return httpsServer;
}