use of org.eclipse.jetty.server.session.HashSessionIdManager in project lucene-solr by apache.
the class JettyWebappTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
System.setProperty("solr.solr.home", SolrJettyTestBase.legacyExampleCollection1SolrHome());
System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
System.setProperty("solr.tests.doContainerStreamCloseAssert", "false");
File dataDir = createTempDir().toFile();
dataDir.mkdirs();
System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
String path = ExternalPaths.WEBAPP_HOME;
server = new Server(port);
// insecure: only use for tests!!!!
server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
new WebAppContext(server, path, context);
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
connector.setIdleTimeout(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
server.setStopAtShutdown(true);
server.start();
port = connector.getLocalPort();
}
use of org.eclipse.jetty.server.session.HashSessionIdManager in project Activiti by Activiti.
the class TestServerUtil method createAndStartServer.
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
log.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
use of org.eclipse.jetty.server.session.HashSessionIdManager in project Activiti by Activiti.
the class BaseJPARestTestCase method createAndStartServer.
public static void createAndStartServer() {
server = new Server(HTTP_SERVER_PORT);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(JPAApplicationConfiguration.class);
applicationContext.refresh();
appContext = applicationContext;
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
log.error("Error starting server", e);
}
}
use of org.eclipse.jetty.server.session.HashSessionIdManager 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.session.HashSessionIdManager 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);
}
Aggregations