use of org.eclipse.jetty.server.HttpConfiguration in project ignite by apache.
the class GridJettyRestProtocol method loadJettyConfiguration.
/**
* Loads jetty configuration from the given URL.
*
* @param cfgUrl URL to load configuration from.
* @throws IgniteCheckedException if load failed.
*/
private void loadJettyConfiguration(@Nullable URL cfgUrl) throws IgniteCheckedException {
if (cfgUrl == null) {
HttpConfiguration httpCfg = new HttpConfiguration();
httpCfg.setSecureScheme("https");
httpCfg.setSecurePort(8443);
httpCfg.setSendServerVersion(true);
httpCfg.setSendDateHeader(true);
String srvPortStr = System.getProperty(IGNITE_JETTY_PORT, "8080");
int srvPort;
try {
srvPort = Integer.parseInt(srvPortStr);
} catch (NumberFormatException ignore) {
throw new IgniteCheckedException("Failed to start Jetty server because IGNITE_JETTY_PORT system property " + "cannot be cast to integer: " + srvPortStr);
}
httpSrv = new Server(new QueuedThreadPool(200, 20));
ServerConnector srvConn = new ServerConnector(httpSrv, new HttpConnectionFactory(httpCfg));
srvConn.setHost(System.getProperty(IGNITE_JETTY_HOST, "localhost"));
srvConn.setPort(srvPort);
srvConn.setIdleTimeout(30000L);
srvConn.setReuseAddress(true);
httpSrv.addConnector(srvConn);
httpSrv.setStopAtShutdown(false);
} else {
XmlConfiguration cfg;
try {
cfg = new XmlConfiguration(cfgUrl);
} catch (FileNotFoundException e) {
throw new IgniteSpiException("Failed to find configuration file: " + cfgUrl, e);
} catch (SAXException e) {
throw new IgniteSpiException("Failed to parse configuration file: " + cfgUrl, e);
} catch (IOException e) {
throw new IgniteSpiException("Failed to load configuration file: " + cfgUrl, e);
} catch (Exception e) {
throw new IgniteSpiException("Failed to start HTTP server with configuration file: " + cfgUrl, e);
}
try {
httpSrv = (Server) cfg.configure();
} catch (Exception e) {
throw new IgniteCheckedException("Failed to start Jetty HTTP server.", e);
}
}
assert httpSrv != null;
httpSrv.setHandler(jettyHnd);
override(getJettyConnector());
}
use of org.eclipse.jetty.server.HttpConfiguration in project lucene-solr by apache.
the class ReplicatorTestCase method newHttpServer.
/**
* Returns a new {@link Server HTTP Server} instance. To obtain its port, use
* {@link #serverPort(Server)}.
*/
public static synchronized Server newHttpServer(Handler handler) throws Exception {
// if this property is true, then jetty will be configured to use SSL
// leveraging the same system properties as java to specify
// the keystore/truststore if they are set
//
// This means we will use the same truststore, keystore (and keys) for
// the server as well as any client actions taken by this JVM in
// talking to that server, but for the purposes of testing that should
// be good enough
final boolean useSsl = Boolean.getBoolean("tests.jettySsl");
final SslContextFactory sslcontext = new SslContextFactory(false);
if (useSsl) {
if (null != System.getProperty("javax.net.ssl.keyStore")) {
sslcontext.setKeyStorePath(System.getProperty("javax.net.ssl.keyStore"));
}
if (null != System.getProperty("javax.net.ssl.keyStorePassword")) {
sslcontext.setKeyStorePassword(System.getProperty("javax.net.ssl.keyStorePassword"));
}
if (null != System.getProperty("javax.net.ssl.trustStore")) {
sslcontext.setKeyStorePath(System.getProperty("javax.net.ssl.trustStore"));
}
if (null != System.getProperty("javax.net.ssl.trustStorePassword")) {
sslcontext.setTrustStorePassword(System.getProperty("javax.net.ssl.trustStorePassword"));
}
sslcontext.setNeedClientAuth(Boolean.getBoolean("tests.jettySsl.clientAuth"));
}
final QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setDaemon(true);
threadPool.setMaxThreads(10000);
threadPool.setIdleTimeout(5000);
threadPool.setStopTimeout(30000);
Server server = new Server(threadPool);
server.setStopAtShutdown(true);
server.manage(threadPool);
final ServerConnector connector;
if (useSsl) {
HttpConfiguration configuration = new HttpConfiguration();
configuration.setSecureScheme("https");
configuration.addCustomizer(new SecureRequestCustomizer());
ServerConnector c = new ServerConnector(server, new SslConnectionFactory(sslcontext, "http/1.1"), new HttpConnectionFactory(configuration));
connector = c;
} else {
ServerConnector c = new ServerConnector(server, new HttpConnectionFactory());
connector = c;
}
connector.setPort(0);
connector.setHost("127.0.0.1");
server.setConnectors(new Connector[] { connector });
server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
server.setHandler(handler);
server.start();
return server;
}
use of org.eclipse.jetty.server.HttpConfiguration in project lucene-solr by apache.
the class JettySolrRunner method init.
private void init(int port) {
QueuedThreadPool qtp = new QueuedThreadPool();
qtp.setMaxThreads(THREAD_POOL_MAX_THREADS);
qtp.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
qtp.setStopTimeout((int) TimeUnit.MINUTES.toMillis(1));
server = new Server(qtp);
server.manage(qtp);
server.setStopAtShutdown(config.stopAtShutdown);
if (System.getProperty("jetty.testMode") != null) {
// if this property is true, then jetty will be configured to use SSL
// leveraging the same system properties as java to specify
// the keystore/truststore if they are set unless specific config
// is passed via the constructor.
//
// This means we will use the same truststore, keystore (and keys) for
// the server as well as any client actions taken by this JVM in
// talking to that server, but for the purposes of testing that should
// be good enough
final SslContextFactory sslcontext = SSLConfig.createContextFactory(config.sslConfig);
ServerConnector connector;
if (sslcontext != null) {
HttpConfiguration configuration = new HttpConfiguration();
configuration.setSecureScheme("https");
configuration.addCustomizer(new SecureRequestCustomizer());
connector = new ServerConnector(server, new SslConnectionFactory(sslcontext, "http/1.1"), new HttpConnectionFactory(configuration));
} else {
connector = new ServerConnector(server, new HttpConnectionFactory());
}
connector.setReuseAddress(true);
connector.setSoLingerTime(-1);
connector.setPort(port);
connector.setHost("127.0.0.1");
connector.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
server.setConnectors(new Connector[] { connector });
server.setSessionIdManager(new HashSessionIdManager(new Random()));
} else {
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
connector.setPort(port);
connector.setSoLingerTime(-1);
connector.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
server.setConnectors(new Connector[] { connector });
}
// Initialize the servlets
final ServletContextHandler root = new ServletContextHandler(server, config.context, ServletContextHandler.SESSIONS);
server.addLifeCycleListener(new LifeCycle.Listener() {
@Override
public void lifeCycleStopping(LifeCycle arg0) {
}
@Override
public void lifeCycleStopped(LifeCycle arg0) {
}
@Override
public void lifeCycleStarting(LifeCycle arg0) {
synchronized (JettySolrRunner.this) {
waitOnSolr = true;
JettySolrRunner.this.notify();
}
}
@Override
public void lifeCycleStarted(LifeCycle arg0) {
lastPort = getFirstConnectorPort();
nodeProperties.setProperty("hostPort", Integer.toString(lastPort));
nodeProperties.setProperty("hostContext", config.context);
root.getServletContext().setAttribute(SolrDispatchFilter.PROPERTIES_ATTRIBUTE, nodeProperties);
root.getServletContext().setAttribute(SolrDispatchFilter.SOLRHOME_ATTRIBUTE, solrHome);
logger.info("Jetty properties: {}", nodeProperties);
debugFilter = root.addFilter(DebugFilter.class, "*", EnumSet.of(DispatcherType.REQUEST));
extraFilters = new LinkedList<>();
for (Class<? extends Filter> filterClass : config.extraFilters.keySet()) {
extraFilters.add(root.addFilter(filterClass, config.extraFilters.get(filterClass), EnumSet.of(DispatcherType.REQUEST)));
}
for (ServletHolder servletHolder : config.extraServlets.keySet()) {
String pathSpec = config.extraServlets.get(servletHolder);
root.addServlet(servletHolder, pathSpec);
}
dispatchFilter = root.getServletHandler().newFilterHolder(BaseHolder.Source.EMBEDDED);
dispatchFilter.setHeldClass(SolrDispatchFilter.class);
dispatchFilter.setInitParameter("excludePatterns", excludePatterns);
root.addFilter(dispatchFilter, "*", EnumSet.of(DispatcherType.REQUEST));
}
@Override
public void lifeCycleFailure(LifeCycle arg0, Throwable arg1) {
System.clearProperty("hostPort");
}
});
// for some reason, there must be a servlet for this to get applied
root.addServlet(Servlet404.class, "/*");
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(root);
gzipHandler.setMinGzipSize(0);
gzipHandler.setCheckGzExists(false);
gzipHandler.setCompressionLevel(-1);
gzipHandler.setExcludedAgentPatterns(".*MSIE.6\\.0.*");
gzipHandler.setIncludedMethods("GET");
server.setHandler(gzipHandler);
}
use of org.eclipse.jetty.server.HttpConfiguration in project XRTB by benmfaul.
the class AddShutdownHook method startSeparateAdminServer.
/**
* Start a different handler for control and reporting functions
*
* @throws Exception
* if SSL is specified but is not configured
*/
void startSeparateAdminServer() throws Exception {
SSL ssl = Configuration.getInstance().ssl;
QueuedThreadPool threadPool = new QueuedThreadPool(threads, 50);
Server server = new Server(threadPool);
ServerConnector connector;
if (Configuration.getInstance().adminPort == 0)
return;
Controller.getInstance().sendLog(1, "initialization", ("Admin functions are available on port: " + Configuration.getInstance().adminPort));
if (!Configuration.getInstance().adminSSL) {
// adminPort
connector = new ServerConnector(server);
connector.setPort(Configuration.getInstance().adminPort);
connector.setIdleTimeout(60000);
server.setConnectors(new Connector[] { connector });
} else {
if (config.getInstance().ssl == null) {
throw new Exception("Admin port set to SSL but no SSL credentials are configured.");
}
Controller.getInstance().sendLog(1, "initialization", "Admin functions are available by SSL only");
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(ssl.setKeyStorePath);
sslContextFactory.setKeyStorePassword(ssl.setKeyStorePassword);
sslContextFactory.setKeyManagerPassword(ssl.setKeyManagerPassword);
ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https));
sslConnector.setPort(Configuration.getInstance().adminPort);
server.setConnectors(new Connector[] { sslConnector });
}
adminHandler = new AdminHandler();
// org.eclipse.jetty.server.session.SessionHandler
SessionHandler sh = new SessionHandler();
sh.setHandler(adminHandler);
// set session handle
server.setHandler(sh);
server.start();
server.join();
}
Aggregations