use of com.sun.net.httpserver.HttpsParameters in project data-transfer-project by google.
the class ReferenceApiServer method createServer.
private HttpServer createServer(int port) throws Exception {
if (trustManagerFactory == null || keyManagerFactory == null) {
return HttpServer.create(new InetSocketAddress(port), 0);
}
HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 0);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
public void configure(HttpsParameters params) {
try {
SSLContext context = SSLContext.getDefault();
SSLEngine engine = context.createSSLEngine();
params.setCipherSuites(engine.getEnabledCipherSuites());
params.setProtocols(engine.getEnabledProtocols());
SSLParameters defaultSSLParameters = context.getDefaultSSLParameters();
params.setSSLParameters(defaultSSLParameters);
params.setNeedClientAuth(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
return server;
}
use of com.sun.net.httpserver.HttpsParameters 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);
params.setProtocols(SSLUtils.getRecommendedProtocols());
params.setCipherSuites(SSLUtils.getRecommendedCiphers());
// 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;
}
Aggregations