/** * Create HTTP connector. * * @return Initialized {@link ServerConnector} instance for HTTP connections. * @throws Exception */ private ServerConnector createHttpConnector(Config config) throws Exception { LOG.info("Setting up HTTP connector for web server"); final HttpConfiguration httpConfig = new HttpConfiguration(); final ServerConnector httpConnector = new ServerConnector(jettyServer, new HttpConnectionFactory(httpConfig)); httpConnector.setPort(config.getInt(DrillOnYarnConfig.HTTP_PORT)); return httpConnector; }
protected HttpConnectionFactory buildHttpConnectionFactory(HttpConfiguration httpConfig) { final HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfig, httpCompliance); httpConnectionFactory.setInputBufferSize((int) inputBufferSize.toBytes()); return httpConnectionFactory; }
private ServerConnector http(final Server server, final Config conf, final String path, final boolean http2) { HttpConfiguration httpConfig = conf(new HttpConfiguration(), conf.withoutPath(CONNECTOR), path); ServerConnector connector; if (http2) { connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig), new HTTP2CServerConnectionFactory(httpConfig)); } else { connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); } return conf(connector, conf.getConfig(CONNECTOR), path + "." + CONNECTOR); }
private static HttpConnectionFactory createHttpConnectionFactory() { HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.addCustomizer(new ForwardedRequestCustomizer()); return new HttpConnectionFactory(httpConfig); }
@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); } }
private ServerConnector createHttp11ServerConnector(Server server, HttpConfiguration config, SslContextFactory sslContextFactory) { HttpConnectionFactory connectionFactory = new HttpConnectionFactory(config); SslConnectionFactory sslConnectionFactory = new SslConnectionFactory( sslContextFactory, HttpVersion.HTTP_1_1.asString()); return new ServerConnector(server, sslConnectionFactory, connectionFactory); }
private ServerConnector createHttpChannelConnector( Server server, HttpConfiguration httpConfig) { ServerConnector conn = new ServerConnector(server, conf.getInt(HTTP_ACCEPTOR_COUNT_KEY, HTTP_ACCEPTOR_COUNT_DEFAULT), conf.getInt(HTTP_SELECTOR_COUNT_KEY, HTTP_SELECTOR_COUNT_DEFAULT)); ConnectionFactory connFactory = new HttpConnectionFactory(httpConfig); conn.addConnectionFactory(connFactory); if(Shell.WINDOWS) { // result of setting the SO_REUSEADDR flag is different on Windows // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx // without this 2 NN's can start on the same machine and listen on // the same port with indeterminate routing of incoming requests to them conn.setReuseAddress(false); } return conn; }
/** * Construct a Jetty Server instance. */ public static Server jettyCreateServer(Integer port, String host, Integer httpsPort, Integer headerBufferSize, Boolean disableHttpBinding) { Server server = new Server(); if (httpsPort == null || httpsPort <= 0 || disableHttpBinding == null || disableHttpBinding == false) { HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSendDateHeader(true); if (null != headerBufferSize) { httpConfig.setRequestHeaderSize(headerBufferSize); } ServerConnector httpConnector = new ServerConnector( server, new HttpConnectionFactory(httpConfig) ); httpConnector.setPort(ObjectReader.getInt(port, 80)); httpConnector.setIdleTimeout(200000); httpConnector.setHost(host); server.addConnector(httpConnector); } return server; }
private Connector createConnector( final Server httpBindServer ) { final int port = getHttpBindUnsecurePort(); if (port > 0) { HttpConfiguration httpConfig = new HttpConfiguration(); configureProxiedConnector(httpConfig); ServerConnector connector = new ServerConnector(httpBindServer, new HttpConnectionFactory(httpConfig)); // Listen on a specific network interface if it has been set. connector.setHost(getBindInterface()); connector.setPort(port); return connector; } else { return null; } }
/** Constructs a server to run with the given ConnectionFactory on the given address/port. */ public HttpServer(ResponderServlet servlet, ConnectionFactory connectionFactory, String bindAddress, int port) throws IOException { this.server = new org.eclipse.jetty.server.Server(); HttpConfiguration httpConfig = new HttpConfiguration(); HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig); ServerConnector connector = new ServerConnector(this.server, connectionFactory, httpFactory); if (bindAddress != null) { connector.setHost(bindAddress); } connector.setPort(port); server.addConnector(connector); ServletHandler handler = new ServletHandler(); server.setHandler(handler); handler.addServletWithMapping(new ServletHolder(servlet), "/*"); }
/** * Configures an HTTP connector and adds it to the server. * * @param server the Jetty server instance * @param httpConfiguration the configuration object for the HTTP protocol settings */ private void configureHttpConnector(Server server, HttpConfiguration httpConfiguration) { String hostname = props.getProperty(NiFiProperties.WEB_HTTP_HOST); final Integer port = props.getPort(); String connectorLabel = "HTTP"; final Map<String, String> httpNetworkInterfaces = props.getHttpNetworkInterfaces(); ServerConnectorCreator<Server, HttpConfiguration, ServerConnector> scc = (s, c) -> new ServerConnector(s, new HttpConnectionFactory(c)); configureGenericConnector(server, httpConfiguration, hostname, port, connectorLabel, httpNetworkInterfaces, scc); }
private ServerConnector createConnector(final SslContextFactory sslContextFactory, final Integer listenPort) { final ServerConnector serverConnector; if (sslContextFactory == null) { serverConnector = new ServerConnector(server); } else { final HttpConfiguration httpsConfiguration = new HttpConfiguration(); httpsConfiguration.setSecureScheme("https"); httpsConfiguration.addCustomizer(new SecureRequestCustomizer()); serverConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfiguration)); } serverConnector.setPort(listenPort); return serverConnector; }
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; }
private ServerConnector createHttp2ServerConnector(Server server, HttpConfiguration config, SslContextFactory sslContextFactory) { HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(config); ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR); sslContextFactory.setProvider("Conscrypt"); SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol()); return new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(config)); }
private Connector plainConnector(Jetty9Server server) { HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setOutputBufferSize(systemEnvironment.get(SystemEnvironment.RESPONSE_BUFFER_SIZE)); httpConfig.setSendServerVersion(false); httpConfig.addCustomizer(new ForwardedRequestCustomizer()); ServerConnector httpConnector = new ServerConnector(server.getServer(), new HttpConnectionFactory(httpConfig)); httpConnector.setHost(systemEnvironment.getListenHost()); httpConnector.setPort(systemEnvironment.getServerPort()); httpConnector.setIdleTimeout(systemEnvironment.get(SystemEnvironment.IDLE_TIMEOUT)); return httpConnector; }
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)); }
public static ServerConnector addHttpsConnector(Server server) throws IOException, URISyntaxException { String keyStoreFile = resourceAsFile("ssltest-keystore.jks").getAbsolutePath(); SslContextFactory sslContextFactory = new SslContextFactory(keyStoreFile); sslContextFactory.setKeyStorePassword("changeit"); String trustStoreFile = resourceAsFile("ssltest-cacerts.jks").getAbsolutePath(); sslContextFactory.setTrustStorePath(trustStoreFile); sslContextFactory.setTrustStorePassword("changeit"); HttpConfiguration httpsConfig = new HttpConfiguration(); httpsConfig.setSecureScheme("https"); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfig)); server.addConnector(connector); return connector; }
server, new SslConnectionFactory(factory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig) ); sslConnector.setPort(port);
private static Server startHttp2() throws Exception { final Server server = new Server(); // Common HTTP configuration. final HttpConfiguration config = new HttpConfiguration(); // HTTP/1.1 support. final HttpConnectionFactory http1 = new HttpConnectionFactory(config); // HTTP/2 cleartext support. final HTTP2CServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(config); // Add the connector. final ServerConnector connector = new ServerConnector(server, http1, http2c); connector.setPort(0); server.addConnector(connector); // Add the servlet. final ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(newServletHolder(thriftServlet), TSERVLET_PATH); server.setHandler(handler); // Start the server. server.start(); return server; }
LOGGER.info("Excluded protocols: {}", StringUtils.join(goSSLConfig.getProtocolsToBeExcluded(), ",")); LOGGER.info("Renegotiation Allowed: {}", goSSLConfig.isRenegotiationAllowed()); ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig)); https.setHost(systemEnvironment.getListenHost()); https.setPort(systemEnvironment.getSslServerPort());