@BeforeClass(alwaysRun = true)
  public void setUpGlobal() throws Exception {
    server = new Server();
    server2 = new Server();

    port1 = findFreePort();
    port2 = findFreePort();

    Connector listener = new SelectChannelConnector();

    listener.setHost("127.0.0.1");
    listener.setPort(port1);

    server.addConnector(listener);

    SslSocketConnector connector = new SslSocketConnector();
    connector.setHost("127.0.0.1");
    connector.setPort(port2);

    ClassLoader cl = getClass().getClassLoader();
    URL keystoreUrl = cl.getResource("ssltest-keystore.jks");
    String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath();
    connector.setKeystore(keyStoreFile);
    connector.setKeyPassword("changeit");
    connector.setKeystoreType("JKS");

    server2.addConnector(connector);

    server.setHandler(configureHandler());
    server.start();

    server2.setHandler(new EchoHandler());
    server2.start();
    log.info("Local HTTP server started successfully");
  }
Пример #2
0
  /**
   * This implementation is based on http://blog.denevell.org/jetty-9-ssl-https.html
   *
   * @throws Exception
   */
  private void startHttps() throws Exception {
    _server = new Server();

    SslContextFactory sslContextFactory = new SslContextFactory(H2O.ARGS.jks);
    sslContextFactory.setKeyStorePassword(H2O.ARGS.jks_pass);

    SslSocketConnector httpsConnector = new SslSocketConnector(sslContextFactory);

    if (getIp() != null) {
      httpsConnector.setHost(getIp());
    }
    httpsConnector.setPort(getPort());

    createServer(httpsConnector);
  }