com.sun.net.httpserver.HttpsConfigurator Java Examples

The following examples show how to use com.sun.net.httpserver.HttpsConfigurator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridEmbeddedHttpServer.java    From ignite with Apache License 2.0 7 votes vote down vote up
/**
 * Internal method which creates and starts the server.
 *
 * @param httpsMode True if the server to be started is HTTPS, false otherwise.
 * @return Started server.
 */
private static GridEmbeddedHttpServer createAndStart(boolean httpsMode) throws Exception {
    HttpServer httpSrv;
    InetSocketAddress addrToBind = new InetSocketAddress(HOSTNAME_TO_BIND_SRV, getAvailablePort());

    if (httpsMode) {
        HttpsServer httpsSrv = HttpsServer.create(addrToBind, 0);

        httpsSrv.setHttpsConfigurator(new HttpsConfigurator(GridTestUtils.sslContext()));

        httpSrv = httpsSrv;
    }
    else
        httpSrv = HttpServer.create(addrToBind, 0);

    GridEmbeddedHttpServer embeddedHttpSrv = new GridEmbeddedHttpServer();

    embeddedHttpSrv.proto = httpsMode ? "https" : "http";
    embeddedHttpSrv.httpSrv = httpSrv;
    embeddedHttpSrv.httpSrv.start();

    return embeddedHttpSrv;
}
 
Example #2
Source File: AggregatorApplication.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
protected HttpServer createHttpServer() throws Exception {
  ResourceConfig resourceConfig = new PackagesResourceConfig("org.apache.hadoop.metrics2.host.aggregator");
  HashMap<String, Object> params = new HashMap();
  params.put("com.sun.jersey.api.json.POJOMappingFeature", "true");
  resourceConfig.setPropertiesAndFeatures(params);
  HttpServer server = HttpServerFactory.create(getURI(), resourceConfig);

  if (webServerProtocol.equalsIgnoreCase("https")) {
    HttpsServer httpsServer = (HttpsServer) server;
    SslContextFactory sslContextFactory = new SslContextFactory();
    String keyStorePath = configuration.get("ssl.server.keystore.location");
    String keyStorePassword = configuration.get("ssl.server.keystore.password");
    String keyManagerPassword = configuration.get("ssl.server.keystore.keypassword");
    String trustStorePath = configuration.get("ssl.server.truststore.location");
    String trustStorePassword = configuration.get("ssl.server.truststore.password");

    sslContextFactory.setKeyStorePath(keyStorePath);
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    sslContextFactory.setKeyManagerPassword(keyManagerPassword);
    sslContextFactory.setTrustStorePath(trustStorePath);
    sslContextFactory.setTrustStorePassword(trustStorePassword);

    sslContextFactory.start();
    SSLContext sslContext = sslContextFactory.getSslContext();
    sslContextFactory.stop();
    HttpsConfigurator httpsConfigurator = new HttpsConfigurator(sslContext);
    httpsServer.setHttpsConfigurator(httpsConfigurator);
    server = httpsServer;
  }
  return server;
}
 
Example #3
Source File: HttpServerCreator.java    From alloc with Apache License 2.0 5 votes vote down vote up
private static HttpsServer createHttpsServer(int port) throws Exception {
    generateCertificate();
    HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(port), 0);
    SSLContext sslContext = getSslContext();
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
    return httpsServer;
}
 
Example #4
Source File: HttpsSocketFacTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #5
Source File: HttpsCreateSockTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #6
Source File: HttpsSocketFacTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #7
Source File: HttpsSocketFacTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #8
Source File: HttpsCreateSockTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #9
Source File: HttpsSocketFacTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #10
Source File: ConsoleProxySecureServerFactoryImpl.java    From cosmic with Apache License 2.0 5 votes vote down vote up
@Override
public HttpServer createHttpServerInstance(final int port) throws IOException {
    try {
        final HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
        server.setHttpsConfigurator(new HttpsConfigurator(ConsoleProxySecureServerFactoryImpl.this.sslContext) {
            @Override
            public void configure(final HttpsParameters params) {
                final SSLContext c = getSSLContext();

                // get the default parameters
                final 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 (final Exception ioe) {
        s_logger.error(ioe.toString(), ioe);
    }
    return null;
}
 
Example #11
Source File: HttpsSocketFacTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #12
Source File: HttpsCreateSockTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #13
Source File: HttpsSocketFacTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #14
Source File: HttpsCreateSockTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #15
Source File: HttpsSocketFacTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #16
Source File: ConsoleProxySecureServerFactoryImpl.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: HttpsCreateSockTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #18
Source File: HttpsCreateSockTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #19
Source File: HttpsSocketFacTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #20
Source File: HttpsCreateSockTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #21
Source File: HttpsSocketFacTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #22
Source File: HttpsCreateSockTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #23
Source File: HttpsSocketFacTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #24
Source File: HttpsCreateSockTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #25
Source File: MetricsEndpointMockServerTLS.java    From promregator with Apache License 2.0 5 votes vote down vote up
public void start() throws IOException {
	InetSocketAddress bindAddress = new InetSocketAddress("127.0.0.1", this.port);
	this.server = HttpsServer.create(bindAddress, 0);
	this.server.setHttpsConfigurator(new HttpsConfigurator(this.createSslContext()) {
		public void configure(HttpsParameters params) {
			SSLContext c = getSSLContext();
			params.setSSLParameters(c.getDefaultSSLParameters());
		}
	});

	this.server.createContext("/metrics", this.getMetricsEndpointHandler());

	this.server.start();
}
 
Example #26
Source File: HttpsSocketFacTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #27
Source File: HttpsCreateSockTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #28
Source File: HttpsSocketFacTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/test6614957/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #29
Source File: HttpsCreateSockTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Https Server
 */
public void startHttpsServer() throws IOException, NoSuchAlgorithmException  {
    httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
    httpsServer.createContext("/", new MyHandler());
    httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
    httpsServer.start();
}
 
Example #30
Source File: SSLStreams.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void configureEngine(HttpsConfigurator cfg, InetSocketAddress addr) {
   if (cfg != null) {
      SSLStreams.Parameters params = new SSLStreams.Parameters(cfg, addr);
      cfg.configure(params);
      SSLParameters sslParams = params.getSSLParameters();
      if (sslParams != null) {
         this.engine.setSSLParameters(sslParams);
      } else {
         if (params.getCipherSuites() != null) {
            try {
               this.engine.setEnabledCipherSuites(params.getCipherSuites());
            } catch (IllegalArgumentException var7) {
               ;
            }
         }

         this.engine.setNeedClientAuth(params.getNeedClientAuth());
         this.engine.setWantClientAuth(params.getWantClientAuth());
         if (params.getProtocols() != null) {
            try {
               this.engine.setEnabledProtocols(params.getProtocols());
            } catch (IllegalArgumentException var6) {
               ;
            }
         }
      }
   }

}