public JettyAdminServer(String address, int port, int timeout, String commandUrl) { this.port = port; this.idleTimeout = timeout; this.commandUrl = commandUrl; this.address = address; server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setHost(address); connector.setPort(port); connector.setIdleTimeout(idleTimeout); server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/*"); server.setHandler(context); context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*"); }
@Override protected void startInternal() throws Exception { this.jettyServer.start(); setPort(((ServerConnector) this.jettyServer.getConnectors()[0]).getLocalPort()); }
for (ListenerInfo li : listeners) { ServerConnector listener = li.listener; if (!li.isManaged || (li.listener.getLocalPort() != -1 && li.listener.getLocalPort() != -2)) { int port = listener.getPort(); while (true) { listener.close(); listener.open(); LOG.info("Jetty bound to port " + listener.getLocalPort()); break; } catch (BindException ex) { if (port == 0 || !findPort) { BindException be = new BindException("Port in use: " + listener.getHost() + ":" + listener.getPort()); be.initCause(ex); throw be; listener.setPort(++port); Thread.sleep(100);
private static void initializeConnector(ServerConnector connector, String host, int port) { // Set some timeout options to make debugging easier. connector.setIdleTimeout(TimeUnit.HOURS.toMillis(1)); connector.setSoLingerTime(-1); connector.setHost(host); connector.setPort(port); }
private static ServerConnector createConnector(Server s, int port){ ServerConnector connector = new ServerConnector(s); connector.setHost("0.0.0.0"); connector.setPort(port); return connector; }
private ServerConnector connector() { ServerConnector connector = new ServerConnector(jettyServer); connector.setPort(port); return connector; }
public void start() throws Exception { server = new Server(); ServerConnector httpConnector = addHttpConnector(server); if (httpPort != 0) { httpConnector.setPort(httpPort); } server.setHandler(new QueueHandler()); ServerConnector httpsConnector = addHttpsConnector(server); if (httpsPort != 0) { httpsConnector.setPort(httpsPort); } server.start(); httpPort = httpConnector.getLocalPort(); httpsPort = httpsConnector.getLocalPort(); }
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); 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, serverConnector = new ServerConnector(server, new SslConnectionFactory(sslCtxFactory, HttpVersion.HTTP_1_1.toString()), new HttpConnectionFactory(httpsConfig)); } else { serverConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); serverConnector.setAcceptQueueSize(acceptQueueSize); serverConnector.setPort(servicePort); serverConnector.setHost(host); server.addConnector(serverConnector);
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});
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); m_server.addConnector(https);
FlumeBeanConfigurator.setConfigurationFields(threadPool, sourceContext); srv = new Server(threadPool); srv.addEventListener(mbContainer); srv.addBean(mbContainer); HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.addCustomizer(new SecureRequestCustomizer()); httpConfiguration.setSecurePort(port); httpConfiguration.setSecureScheme("https"); return new ServerConnector(srv, new SslConnectionFactory(sslCtxFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpConfiguration)); }).orElse( new ServerConnector(srv, new HttpConnectionFactory(httpConfiguration)) ); connector.setPort(port); connector.setHost(host); connector.setReuseAddress(true);
@Override public void start() { jettyServer = new Server(); //We can use Contexts etc if we have many urls to handle. For one url, //specifying a handler directly is the most efficient. HttpConfiguration httpConfiguration = new HttpConfiguration(); ServerConnector connector = new ServerConnector(jettyServer, new HttpConnectionFactory(httpConfiguration)); connector.setReuseAddress(true); connector.setPort(port); jettyServer.addConnector(connector); jettyServer.setHandler(new HTTPMetricsHandler()); try { jettyServer.start(); while (!jettyServer.isStarted()) { Thread.sleep(500); } } catch (Exception ex) { LOG.error("Error starting Jetty. JSON Metrics may not be available.", ex); } }
this.httpServer = new Server(); httpServer.setHandler(new HandlerCollection(true)); ServerConnector connector = null; 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); } else { connector = new ServerConnector(httpServer, new HttpConnectionFactory(httpConfig)); connector.setPort(port); httpServer.setConnectors(new Connector[] {connector}); connector.setHost(bindAddress);
public void start() { if (useHttps) { server = new Server(); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyStorePassword("password"); sslContextFactory.setKeyManagerPassword("password"); HttpConfiguration https = new HttpConfiguration(); ServerConnector sslConnector = new ServerConnector( server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https)); sslConnector.setPort(httpPort); server.setConnectors(new Connector[] {sslConnector}); } else { server = new Server(httpPort); ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(new HttpConfiguration())); connector.setPort(httpPort); server.setConnectors(new Connector[] {connector});
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) new Request( HttpMethod.GET, new URL(StringUtils.format("https://127.0.0.1:%d/", sslConnector.getLocalPort())) ), new StatusResponseHandler(StandardCharsets.UTF_8) 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);
private void start() throws Exception { server = new Server(); ServerConnector connector = new ServerConnector(server); server.addConnector(connector); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setCertAlias("cruise"); sslContextFactory.setKeyStoreResource(Resource.newClassPathResource("testdata/fake-server-keystore")); sslContextFactory.setKeyStorePassword("serverKeystorepa55w0rd"); ServerConnector secureConnnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(new HttpConfiguration()) ); server.addConnector(secureConnnector); server.start(); port = connector.getLocalPort(); securePort = secureConnnector.getLocalPort();
ServerConnector connector = new ServerConnector(LoklakInstallation.server); connector.addConnectionFactory(new HttpConnectionFactory(http_config)); connector.setPort(httpPort); connector.setName("httpd:" + httpPort); connector.setIdleTimeout(20000); // timout in ms when no bytes send / received LoklakInstallation.server.addConnector(connector); 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"); ServerConnector sslConnector = new ServerConnector(LoklakInstallation.server, ssl, http1); sslConnector.setPort(httpsPort); sslConnector.setName("httpd:" + httpsPort); sslConnector.setIdleTimeout(20000); // timout in ms when no bytes send / received LoklakInstallation.server.addConnector(sslConnector);
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, serverConnector = new ServerConnector(httpServer, new SslConnectionFactory(sslCtxFactory, HttpVersion.HTTP_1_1.toString()), new HttpConnectionFactory(httpsConfig)); } else { serverConnector = new ServerConnector(httpServer, new HttpConnectionFactory(httpConfig)); serverConnector.setPort(listenPort); serverConnector.setHost(getBindAddress(conf).getHostAddress()); httpServer.addConnector(serverConnector); httpServer.setStopAtShutdown(true);