Search in sources :

Example 11 with HttpsConfigurator

use of com.sun.net.httpserver.HttpsConfigurator in project cloudstack by apache.

the class ConsoleProxySecureServerFactoryImpl method createHttpServerInstance.

@Override
public HttpServer createHttpServerInstance(int port) throws IOException {
    try {
        HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
        server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {

            @Override
            public void configure(HttpsParameters params) {
                // get the remote address if needed
                InetSocketAddress remote = params.getClientAddress();
                SSLContext c = getSSLContext();
                // get the default parameters
                SSLParameters sslparams = c.getDefaultSSLParameters();
                params.setSSLParameters(sslparams);
            // statement above could throw IAE if any params invalid.
            // eg. if app has a UI and parameters supplied by a user.
            }
        });
        s_logger.info("create HTTPS server instance on port: " + port);
        return server;
    } catch (Exception ioe) {
        s_logger.error(ioe.toString(), ioe);
    }
    return null;
}
Also used : HttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator) SSLParameters(javax.net.ssl.SSLParameters) InetSocketAddress(java.net.InetSocketAddress) HttpsParameters(com.sun.net.httpserver.HttpsParameters) SSLContext(javax.net.ssl.SSLContext) HttpsServer(com.sun.net.httpserver.HttpsServer) IOException(java.io.IOException)

Aggregations

HttpsConfigurator (com.sun.net.httpserver.HttpsConfigurator)11 InetSocketAddress (java.net.InetSocketAddress)9 SSLContext (javax.net.ssl.SSLContext)6 HttpsServer (com.sun.net.httpserver.HttpsServer)5 HttpsParameters (com.sun.net.httpserver.HttpsParameters)4 IOException (java.io.IOException)4 SSLParameters (javax.net.ssl.SSLParameters)4 Headers (com.sun.net.httpserver.Headers)2 HttpServer (com.sun.net.httpserver.HttpServer)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 BeforeClass (org.junit.BeforeClass)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 HttpHandler (com.sun.net.httpserver.HttpHandler)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 StringWriter (java.io.StringWriter)1 BindException (java.net.BindException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStore (java.security.KeyStore)1