Server server = new Server(); handlers.setHandlers(new Handler[]{staticResourceHandler, servletContextHandler}); server.setHandler(handlers); HttpConfiguration http_config = new HttpConfiguration(); http_config.setSecureScheme("https"); http_config.setSecurePort(Integer.parseInt(globalProps.getProperty("serverPort"))); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath()); sslContextFactory.setKeyStorePassword(globalProps.getProperty("keystorePwd")); sslContextFactory.setKeyManagerPassword(globalProps.getProperty("keystoreManagerPwd")); HttpConfiguration https_config = new HttpConfiguration(http_config); https_config.addCustomizer(new SecureRequestCustomizer()); ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config)); https.setPort(Integer.parseInt(globalProps.getProperty("serverPort"))); server.setConnectors(new Connector[]{https}); } else { if(globalProps.getProperty("X-Forwarded-For").equals("true")) { http_config.addCustomizer(new org.eclipse.jetty.server.ForwardedRequestCustomizer()); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); http.setPort(Integer.parseInt(globalProps.getProperty("serverPort"))); server.setConnectors(new Connector[]{http});
private void setUpSSlServer2() throws Exception { server2 = new Server(); HttpConfiguration https_config = new HttpConfiguration(); https_config.setSecureScheme("https"); https_config.setSecurePort(port2); https_config.setOutputBufferSize(32768); SecureRequestCustomizer src = new SecureRequestCustomizer(); src.setStsMaxAge(2000); src.setStsIncludeSubDomains(true); https_config.addCustomizer(src); SslContextFactory sslContextFactory = new SslContextFactory(); ClassLoader cl = getClass().getClassLoader(); URL cacertsUrl = cl.getResource("ssltest-cacerts.jks"); String trustStoreFile = new File(cacertsUrl.toURI()).getAbsolutePath(); sslContextFactory.setTrustStorePath(trustStoreFile); sslContextFactory.setTrustStorePassword("changeit"); sslContextFactory.setTrustStoreType("JKS"); ServerConnector https_connector = new ServerConnector(server2, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config)); https_connector.setPort(port2); https_connector.setIdleTimeout(500000); setUpServers(https_connector);
Server server = new Server(); HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setSendServerVersion(false); httpConfiguration.setSendXPoweredBy(false); httpConfiguration.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslContextFactory = new SslContextFactory(keystore); sslContextFactory.setKeyStorePassword("changeit"); SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, "http/1.1"); connector = new ServerConnector(server, sslConnectionFactory, new HttpConnectionFactory(httpConfiguration)); HttpConnectionFactory http1 = new HttpConnectionFactory(httpConfiguration); HTTP2CServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(httpConfiguration); connector = new ServerConnector(server, http1, http2c); connector.setIdleTimeout(30000); connector.setName(scheme); server.addConnector(connector); HandlerCollection handlers = new HandlerCollection(); handlers.addHandler(context); server.setHandler(handlers);
final Server server = new Server(new JettyConnectorThreadPool()); final HttpConfiguration config = new HttpConfiguration(); if (sslContextFactory != null) { config.setSecureScheme("https"); config.setSecurePort(port); config.addCustomizer(new SecureRequestCustomizer()); final ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(config)); https.setPort(port); server.setConnectors(new Connector[]{https}); final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(config)); http.setPort(port); server.setConnectors(new Connector[]{http});
new QueuedThreadPool(maxThreads, minThreads, idleTimeout); Server server = new Server(threadPool); server.addEventListener(mbContainer); server.addBean(mbContainer); HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(servicePort); httpConfig.setSendServerVersion(false); httpConfig.setSendDateHeader(false); if (conf.getBoolean(REST_SSL_ENABLED, false)) { HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslCtxFactory = new SslContextFactory(); String keystore = conf.get(REST_SSL_KEYSTORE_STORE); String password = HBaseConfiguration.getPassword(conf, String keyPassword = HBaseConfiguration.getPassword(conf, REST_SSL_KEYSTORE_KEYPASSWORD, password); sslCtxFactory.setKeyStorePath(keystore); sslCtxFactory.setKeyStorePassword(password); sslCtxFactory.setKeyManagerPassword(keyPassword); serverConnector.setAcceptQueueSize(acceptQueueSize);
m_server = new Server(m_pool); else m_server = new Server(); m_server.addBean(errorHandler); ServerConnector http = new ServerConnector(m_server); http.setHost(m_address.getHostName()); http.setPort(m_port); m_server.addConnector(http); HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(m_sslPort); httpConfig.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(m_keyStorePath); sslContextFactory.setKeyStorePassword(m_keyStorePassword); sslContextFactory.setIncludeProtocols(m_protocols); ServerConnector https = new ServerConnector(m_server, new SslConnectionFactory(sslContextFactory,"http/1.1"), new HttpConnectionFactory(httpConfig)); https.setPort(m_sslPort);
FlumeBeanConfigurator.setConfigurationFields(threadPool, sourceContext); srv = new Server(threadPool); srv.addEventListener(mbContainer); srv.addBean(mbContainer); HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslCtxFactory = new SslContextFactory(); sslCtxFactory.setSslContext(sslContext); sslCtxFactory.setExcludeProtocols(getExcludeProtocols().toArray(new String[]{})); sslCtxFactory.setIncludeProtocols(getIncludeProtocols().toArray(new String[]{})); sslCtxFactory.setExcludeCipherSuites(getExcludeCipherSuites().toArray(new String[]{})); httpConfiguration.setSecurePort(port); httpConfiguration.setSecureScheme("https"); connector.setPort(port); connector.setHost(host); connector.setReuseAddress(true);
private ServerConnector createUnconfiguredSslServerConnector(Server server, HttpConfiguration httpConfiguration, int port) { // add some secure config final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration); httpsConfiguration.setSecureScheme("https"); httpsConfiguration.setSecurePort(port); httpsConfiguration.addCustomizer(new SecureRequestCustomizer()); // build the connector return new ServerConnector(server, new SslConnectionFactory(createSslContextFactory(), "http/1.1"), new HttpConnectionFactory(httpsConfiguration)); }
this.httpServer = new Server(); httpServer.setHandler(new HandlerCollection(true)); ServerConnector connector = null; HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme(HTTPS); httpConfig.setSecurePort(port); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setCertAlias(sslConfig.getAlias()); sslContextFactory.setNeedClientAuth(sslConfig.isRequireAuth()); logger.debug(sslContextFactory.dump()); httpConfig.addCustomizer(new SecureRequestCustomizer()); connector = new ServerConnector(httpServer, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpConfig)); connector.setPort(port); httpServer.setConnectors(new Connector[] {connector});
server = new Server(); HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setOutputBufferSize(32768); ); ServerConnector httpConn = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); httpConn.setHost(config.host); httpConn.setPort(config.http); httpConn.setIdleTimeout(30000); server.addConnector(httpConn); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(config.https); SslContextFactory sslFactory = new SslContextFactory(); sslFactory.setKeyStorePath(loc); sslFactory.setKeyStorePassword(pw); sslFactory.setKeyManagerPassword(mgrPw); HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); SecureRequestCustomizer src = new SecureRequestCustomizer(); src.setStsMaxAge(2000); src.setStsIncludeSubDomains(true); httpsConfig.addCustomizer(src);
tp.setName("Jetty-QTP-AdminConsole"); adminServer = new Server(tp); adminServer.addBean(jmx.getContainer()); final HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSendServerVersion( false ); final ServerConnector httpConnector = new ServerConnector(adminServer, null, null, null, -1, serverThreads, new HttpConnectionFactory(httpConfig)); httpConnector.setHost(bindInterface); httpConnector.setPort(adminPort); adminServer.addConnector(httpConnector); final SslContextFactory sslContextFactory = new EncryptionArtifactFactory( configuration ).getSslContextFactory(); final HttpConfiguration httpsConfig = new HttpConfiguration(); httpsConfig.setSendServerVersion( false ); httpsConfig.setSecureScheme( "https" ); httpsConfig.setSecurePort( adminSecurePort ); httpsConfig.addCustomizer( new SecureRequestCustomizer() ); final HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory( httpsConfig ); final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory( sslContextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_1_1.toString() ); final ServerConnector httpsConnector = new ServerConnector( adminServer, null, null, null, -1, serverThreads, sslConnectionFactory, httpConnectionFactory );
private static Server createServer(Handler handler, int port, KeyStore keyStore, String keyPassword) throws Exception { Server server = new Server(); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setIncludeProtocols("TLSv1.2"); sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyManagerPassword(keyPassword); HttpConfiguration httpsConfig = new HttpConfiguration(); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig)); sslConnector.setPort(port); server.addConnector(sslConnector); server.setHandler(handler); return server; }
Server server = new Server(); HttpConfiguration https = new HttpConfiguration(); https.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(keyStorePath); sslContextFactory.setKeyStorePassword("abc123"); sslContextFactory.setKeyManagerPassword("abc123"); ServerConnector sslConnector = new ServerConnector( server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https) ); sslConnector.setPort(0); server.setConnectors(new Connector[]{sslConnector}); server.start(); new Request( HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", sslConnector.getLocalPort())) ), new StatusResponseHandler(StandardCharsets.UTF_8)
final SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setNeedClientAuth(needClientAuth); contextFactory.setTrustStorePath(sslContextService.getTrustStoreFile()); contextFactory.setTrustStoreType(sslContextService.getTrustStoreType()); contextFactory.setTrustStorePassword(sslContextService.getTrustStorePassword()); final Server server = new Server(threadPool); final HttpConfiguration httpConfiguration = new HttpConfiguration(); if (keystorePath == null) { connector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration)); } else { httpConfiguration.setSecureScheme("https"); httpConfiguration.setSecurePort(port); httpConfiguration.addCustomizer(new SecureRequestCustomizer()); connector = new ServerConnector(server, new SslConnectionFactory(contextFactory, "http/1.1"), new HttpConnectionFactory(httpConfiguration)); connector.setPort(port); server.setConnectors(new Connector[] {connector}); server.start(); } catch (Exception e) { shutdownHttpServer(server);
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads); threadPool.setMinThreads(minThreads); httpServer = new Server(threadPool); HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(listenPort); httpConfig.setHeaderCacheSize(DEFAULT_HTTP_MAX_HEADER_SIZE); httpConfig.setRequestHeaderSize(DEFAULT_HTTP_MAX_HEADER_SIZE); if(conf.getBoolean(THRIFT_SSL_ENABLED_KEY, false)) { HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslCtxFactory = new SslContextFactory(); String keystore = conf.get(THRIFT_SSL_KEYSTORE_STORE_KEY); String password = HBaseConfiguration.getPassword(conf, String keyPassword = HBaseConfiguration.getPassword(conf, THRIFT_SSL_KEYSTORE_KEYPASSWORD_KEY, password); sslCtxFactory.setKeyStorePath(keystore); sslCtxFactory.setKeyStorePassword(password); sslCtxFactory.setKeyManagerPassword(keyPassword); serverConnector.setPort(listenPort); serverConnector.setHost(getBindAddress(conf).getHostAddress()); httpServer.addConnector(serverConnector); httpServer.setStopAtShutdown(true);
final Server server = new Server(threadPool); server.addBean(new ScheduledExecutorScheduler("JettyScheduler", true), true); HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setRequestHeaderSize(config.getMaxRequestHeaderSize()); final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration)); if (node.isBindOnHost()) { connector.setHost(node.getHost()); connector.setPort(node.getPlaintextPort()); serverConnectors.add(connector); final HttpConfiguration httpsConfiguration = new HttpConfiguration(); httpsConfiguration.setSecureScheme("https"); httpsConfiguration.setSecurePort(node.getTlsPort()); httpsConfiguration.addCustomizer(new SecureRequestCustomizer()); httpsConfiguration.setRequestHeaderSize(config.getMaxRequestHeaderSize()); final ServerConnector connector = new ServerConnector( server, new SslConnectionFactory(sslContextFactory, HTTP_1_1_STRING), new HttpConnectionFactory(httpsConfiguration) ); if (node.isBindOnHost()) { server.setConnectors(connectors); final long gracefulStop = config.getGracefulShutdownTimeout().toStandardDuration().getMillis(); if (gracefulStop > 0) {
private static void setupHttpServer(int httpPort, int httpsPort) throws Exception{ QueuedThreadPool pool = new QueuedThreadPool(); pool.setMaxThreads(500); LoklakInstallation.server = new Server(pool); LoklakInstallation.server.setStopAtShutdown(true); HttpConfiguration http_config = new HttpConfiguration(); if(httpsMode.equals(HttpsMode.REDIRECT)) { //redirect http_config.addCustomizer(new SecureRequestCustomizer()); http_config.setSecureScheme("https"); http_config.setSecurePort(httpsPort); HttpConfiguration https_config = new HttpConfiguration(); https_config.addCustomizer(new SecureRequestCustomizer()); HttpConnectionFactory http1 = new HttpConnectionFactory(https_config); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyManagerPassword(keystoreManagerPass); SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, "http/1.1");
@BeforeEach void setUp() throws Exception { server = new Server(); final SslContextFactory sslContextFactory = new SslContextFactory(getClass().getResource("/keystore").getPath()); sslContextFactory.setKeyStorePassword("password"); sslContextFactory.getSslContext(); final HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setSecureScheme("https"); httpConfiguration.setSecurePort(0); final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration); httpsConfiguration.addCustomizer(new SecureRequestCustomizer()); final ServerConnector httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfiguration)); httpsConnector.setPort(0); server.addConnector(httpsConnector); server.setHandler(new AbstractHandler() { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { baseRequest.setHandled(true); requestHandled.set(true); } }); server.start(); configuration = SpyConfiguration.createSpyConfig(); reporterConfiguration = configuration.getConfig(ReporterConfiguration.class); when(reporterConfiguration.getServerUrls()).thenReturn(Collections.singletonList(new URL("https://localhost:" + getPort()))); }
Server server = new Server(); HttpConfiguration http_config = new HttpConfiguration(); http_config.setSecureScheme("https"); http_config.setSecurePort(8443); http_config.setOutputBufferSize(32768); HttpConfiguration https_config = new HttpConfiguration(); https_config.addCustomizer(new SecureRequestCustomizer()); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); http.setPort(8080); http.setIdleTimeout(30000); SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStorePath("keystore.jks"); contextFactory.setKeyStorePassword("changeit"); SslConnectionFactory connectionFactory = new SslConnectionFactory(contextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_1_1.toString()); ServerConnector https = new ServerConnector(server, connectionFactory, new HttpConnectionFactory(https_config)); https.setPort(8443); https.setIdleTimeout(50000); server.setConnectors(new Connector[]{http, https}); ServletContextHandler servletCH = new ServletContextHandler(); servletCH.setContextPath("/"); servletCH.addServlet(ScheduleWebSocketServlet.class, "/schedule"); server.setHandler(servletCH); server.start(); http.start(); https.start(); server.join();
jetty = new Server(); ServerConnector http = new ServerConnector(jetty); http.setPort(port); http.setIdleTimeout(idleTimeout); if (host != null) { http.setHost(host); jetty.addConnector(http); HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(sslPort); httpConfig.setOutputBufferSize(32768); HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStore(StandaloneHelper.loadKeyStore(this.sslKeystoreUri, this.sslKeystorePassword.toCharArray())); sslContextFactory.setKeyManagerPassword(this.sslKeystorePassword); sslContextFactory.setTrustStore(StandaloneHelper.loadKeyStore(this.sslTruststoreUri, this.sslTruststorePassword.toCharArray())); https.setPort(sslPort); https.setIdleTimeout(idleTimeout); jetty.addConnector(https);