use of org.eclipse.jetty.util.thread.QueuedThreadPool in project hadoop by apache.
the class TestWebAppProxyServlet method start.
/**
* Simple http server. Server should send answer with status 200
*/
@BeforeClass
public static void start() throws Exception {
server = new Server(0);
((QueuedThreadPool) server.getThreadPool()).setMaxThreads(10);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/foo");
server.setHandler(context);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
((ServerConnector) server.getConnectors()[0]).setHost("localhost");
server.start();
originalPort = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
LOG.info("Running embedded servlet container at: http://localhost:" + originalPort);
// This property needs to be set otherwise CORS Headers will be dropped
// by HttpUrlConnection
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project hbase by apache.
the class HttpServer method setThreads.
/**
* Set the min, max number of worker threads (simultaneous connections).
*/
public void setThreads(int min, int max) {
QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool();
pool.setMinThreads(min);
pool.setMaxThreads(max);
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project hive by apache.
the class HttpServer method initializeWebServer.
void initializeWebServer(Builder b) {
// Create the thread pool for the web server to handle HTTP requests
QueuedThreadPool threadPool = new QueuedThreadPool();
if (b.maxThreads > 0) {
threadPool.setMaxThreads(b.maxThreads);
}
threadPool.setDaemon(true);
threadPool.setName(b.name + "-web");
webServer.setThreadPool(threadPool);
// Create the channel connector for the web server
Connector connector = createChannelConnector(threadPool.getMaxThreads(), b);
connector.setHost(b.host);
connector.setPort(b.port);
webServer.addConnector(connector);
RewriteHandler rwHandler = new RewriteHandler();
rwHandler.setRewriteRequestURI(true);
rwHandler.setRewritePathInfo(false);
RewriteRegexRule rootRule = new RewriteRegexRule();
rootRule.setRegex("^/$");
rootRule.setReplacement(b.contextRootRewriteTarget);
rootRule.setTerminating(true);
rwHandler.addRule(rootRule);
rwHandler.setHandler(webAppContext);
// Configure web application contexts for the web server
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.addHandler(rwHandler);
webServer.setHandler(contexts);
addServlet("jmx", "/jmx", JMXJsonServlet.class);
addServlet("conf", "/conf", ConfServlet.class);
addServlet("stacks", "/stacks", StackServlet.class);
for (Pair<String, Class<? extends HttpServlet>> p : b.servlets) {
addServlet(p.getFirst(), "/" + p.getFirst(), p.getSecond());
}
ServletContextHandler staticCtx = new ServletContextHandler(contexts, "/static");
staticCtx.setResourceBase(appDir + "/static");
staticCtx.addServlet(DefaultServlet.class, "/*");
staticCtx.setDisplayName("static");
String logDir = getLogDir(b.conf);
if (logDir != null) {
ServletContextHandler logCtx = new ServletContextHandler(contexts, "/logs");
setContextAttributes(logCtx.getServletContext(), b.contextAttrs);
logCtx.addServlet(AdminAuthorizedServlet.class, "/*");
logCtx.setResourceBase(logDir);
logCtx.setDisplayName("logs");
}
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project dropwizard by dropwizard.
the class HttpsConnectorFactoryTest method testBuild.
@Test
public void testBuild() throws Exception {
final HttpsConnectorFactory https = new HttpsConnectorFactory();
https.setBindHost("127.0.0.1");
https.setPort(8443);
https.setKeyStorePath("/etc/app/server.ks");
https.setKeyStoreType("JKS");
https.setKeyStorePassword("correct_horse");
https.setKeyStoreProvider("BC");
https.setTrustStorePath("/etc/app/server.ts");
https.setTrustStoreType("JKS");
https.setTrustStorePassword("battery_staple");
https.setTrustStoreProvider("BC");
https.setKeyManagerPassword("new_overlords");
https.setNeedClientAuth(true);
https.setWantClientAuth(true);
https.setCertAlias("alt_server");
https.setCrlPath(new File("/etc/ctr_list.txt"));
https.setEnableCRLDP(true);
https.setEnableOCSP(true);
https.setMaxCertPathLength(4);
https.setOcspResponderUrl(new URI("http://windc1/ocsp"));
https.setJceProvider("BC");
https.setAllowRenegotiation(false);
https.setEndpointIdentificationAlgorithm("HTTPS");
https.setValidateCerts(true);
https.setValidatePeers(true);
https.setSupportedProtocols(ImmutableList.of("TLSv1.1", "TLSv1.2"));
https.setSupportedCipherSuites(ImmutableList.of("TLS_DHE_RSA.*", "TLS_ECDHE.*"));
final Server server = new Server();
final MetricRegistry metrics = new MetricRegistry();
final ThreadPool threadPool = new QueuedThreadPool();
final Connector connector = https.build(server, metrics, "test-https-connector", threadPool);
assertThat(connector).isInstanceOf(ServerConnector.class);
final ServerConnector serverConnector = (ServerConnector) connector;
assertThat(serverConnector.getPort()).isEqualTo(8443);
assertThat(serverConnector.getHost()).isEqualTo("127.0.0.1");
assertThat(serverConnector.getName()).isEqualTo("test-https-connector");
assertThat(serverConnector.getServer()).isSameAs(server);
assertThat(serverConnector.getScheduler()).isInstanceOf(ScheduledExecutorScheduler.class);
assertThat(serverConnector.getExecutor()).isSameAs(threadPool);
final Jetty93InstrumentedConnectionFactory jetty93SslConnectionFacttory = (Jetty93InstrumentedConnectionFactory) serverConnector.getConnectionFactory("ssl");
assertThat(jetty93SslConnectionFacttory).isInstanceOf(Jetty93InstrumentedConnectionFactory.class);
assertThat(jetty93SslConnectionFacttory.getTimer()).isSameAs(metrics.timer("org.eclipse.jetty.server.HttpConnectionFactory.127.0.0.1.8443.connections"));
final SslContextFactory sslContextFactory = ((SslConnectionFactory) jetty93SslConnectionFacttory.getConnectionFactory()).getSslContextFactory();
assertThat(getField(SslContextFactory.class, "_keyStoreResource", true).get(sslContextFactory)).isEqualTo(Resource.newResource("/etc/app/server.ks"));
assertThat(sslContextFactory.getKeyStoreType()).isEqualTo("JKS");
assertThat(getField(SslContextFactory.class, "_keyStorePassword", true).get(sslContextFactory).toString()).isEqualTo("correct_horse");
assertThat(sslContextFactory.getKeyStoreProvider()).isEqualTo("BC");
assertThat(getField(SslContextFactory.class, "_trustStoreResource", true).get(sslContextFactory)).isEqualTo(Resource.newResource("/etc/app/server.ts"));
assertThat(sslContextFactory.getKeyStoreType()).isEqualTo("JKS");
assertThat(getField(SslContextFactory.class, "_trustStorePassword", true).get(sslContextFactory).toString()).isEqualTo("battery_staple");
assertThat(sslContextFactory.getKeyStoreProvider()).isEqualTo("BC");
assertThat(getField(SslContextFactory.class, "_keyManagerPassword", true).get(sslContextFactory).toString()).isEqualTo("new_overlords");
assertThat(sslContextFactory.getNeedClientAuth()).isTrue();
assertThat(sslContextFactory.getWantClientAuth()).isTrue();
assertThat(sslContextFactory.getCertAlias()).isEqualTo("alt_server");
assertThat(sslContextFactory.getCrlPath()).isEqualTo(new File("/etc/ctr_list.txt").getAbsolutePath());
assertThat(sslContextFactory.isEnableCRLDP()).isTrue();
assertThat(sslContextFactory.isEnableOCSP()).isTrue();
assertThat(sslContextFactory.getMaxCertPathLength()).isEqualTo(4);
assertThat(sslContextFactory.getOcspResponderURL()).isEqualTo("http://windc1/ocsp");
assertThat(sslContextFactory.getProvider()).isEqualTo("BC");
assertThat(sslContextFactory.isRenegotiationAllowed()).isFalse();
assertThat(getField(SslContextFactory.class, "_endpointIdentificationAlgorithm", true).get(sslContextFactory)).isEqualTo("HTTPS");
assertThat(sslContextFactory.isValidateCerts()).isTrue();
assertThat(sslContextFactory.isValidatePeerCerts()).isTrue();
assertThat(sslContextFactory.getIncludeProtocols()).containsOnly("TLSv1.1", "TLSv1.2");
assertThat(sslContextFactory.getIncludeCipherSuites()).containsOnly("TLS_DHE_RSA.*", "TLS_ECDHE.*");
final ConnectionFactory httpConnectionFactory = serverConnector.getConnectionFactory("http/1.1");
assertThat(httpConnectionFactory).isInstanceOf(HttpConnectionFactory.class);
final HttpConfiguration httpConfiguration = ((HttpConnectionFactory) httpConnectionFactory).getHttpConfiguration();
assertThat(httpConfiguration.getSecureScheme()).isEqualTo("https");
assertThat(httpConfiguration.getSecurePort()).isEqualTo(8443);
assertThat(httpConfiguration.getCustomizers()).hasAtLeastOneElementOfType(SecureRequestCustomizer.class);
connector.stop();
server.stop();
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.
the class AbstractHttpClientServerTest method start.
public void start(Handler handler) throws Exception {
server = new Server();
ServerFCGIConnectionFactory fcgiConnectionFactory = new ServerFCGIConnectionFactory(new HttpConfiguration());
serverBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
connector = new ServerConnector(server, null, null, serverBufferPool, 1, Math.max(1, Runtime.getRuntime().availableProcessors() / 2), fcgiConnectionFactory);
// connector.setPort(9000);
server.addConnector(connector);
server.setHandler(handler);
server.start();
QueuedThreadPool executor = new QueuedThreadPool();
executor.setName(executor.getName() + "-client");
client = new HttpClient(new HttpClientTransportOverFCGI(1, false, "") {
@Override
public HttpDestination newHttpDestination(Origin origin) {
return new HttpDestinationOverFCGI(client, origin) {
@Override
protected DuplexConnectionPool newConnectionPool(HttpClient client) {
return new LeakTrackingConnectionPool(this, client.getMaxConnectionsPerDestination(), this) {
@Override
protected void leaked(LeakDetector.LeakInfo leakInfo) {
connectionLeaks.incrementAndGet();
}
};
}
};
}
}, null);
client.setExecutor(executor);
clientBufferPool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
client.setByteBufferPool(clientBufferPool);
client.start();
}
Aggregations