static HttpServer createDashboardHttpServer(Config config) throws IOException { boolean secure = config.isServerSecure(); HttpServer server; if (!secure) { server = HttpServer.create(); } else { server = HttpsServer.create(); SSLContext defaultSslContext; try { defaultSslContext = SSLContext.getDefault(); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } HttpsConfigurator httpsConf = new HttpsConfigurator(defaultSslContext); ((HttpsServer) server).setHttpsConfigurator(httpsConf); } // The Dashboard is on a separate port to prevent malicious HTML documents // in the user's repository from performing admin actions with // XMLHttpRequest or the like, as the HTML page will then be blocked by // same-origin policies. try { server.bind(new InetSocketAddress(config.getServerDashboardPort()), 0); } catch (BindException ex) { log.log( Level.WARNING, "Server dashboard port {0,number,#} is in use.", config.getServerDashboardPort()); throw ex; } // Use separate Executor for Dashboard to allow the administrator to // investigate why things are going wrong without waiting on the normal work // queue. int maxThreads = 4; Executor executor = new ThreadPoolExecutor( maxThreads, maxThreads, 10, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>()); server.setExecutor(executor); log.info("dashboard is listening on port #" + server.getAddress().getPort()); return server; }
static HttpServer createHttpServer(Config config) throws IOException { HttpServer server; if (!config.isServerSecure()) { server = HttpServer.create(); } else { server = HttpsServer.create(); try { HttpsConfigurator httpsConf = new HttpsConfigurator(SSLContext.getDefault()) { public void configure(HttpsParameters params) { SSLParameters sslParams = getSSLContext().getDefaultSSLParameters(); // Allow verifying the GSA and other trusted computers. sslParams.setWantClientAuth(true); params.setSSLParameters(sslParams); } }; ((HttpsServer) server).setHttpsConfigurator(httpsConf); } catch (java.security.NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } } int maxThreads = config.getServerMaxWorkerThreads(); int queueCapacity = config.getServerQueueCapacity(); BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(queueCapacity); // The Executor can't reject jobs directly, because HttpServer does not // appear to handle that case. RejectedExecutionHandler policy = new SuggestHandlerAbortPolicy(HttpExchanges.abortImmediately); Executor executor = new ThreadPoolExecutor(maxThreads, maxThreads, 1, TimeUnit.MINUTES, blockingQueue, policy); server.setExecutor(executor); try { server.bind(new InetSocketAddress(config.getServerPort()), 0); } catch (BindException ex) { log.log(Level.WARNING, "Server port {0,number,#} is in use.", config.getServerPort()); throw ex; } log.info("GSA host name: " + config.getGsaHostname()); log.info("server is listening on port #" + server.getAddress().getPort()); return server; }