use of org.eclipse.jetty.server.Connector in project hive by apache.
the class HttpServer method initializeWebServer.
private void initializeWebServer(final Builder b, int queueSize) throws IOException {
// Set handling for low resource conditions.
final LowResourceMonitor low = new LowResourceMonitor(webServer);
low.setLowResourcesIdleTimeout(10000);
webServer.addBean(low);
Connector connector = createChannelConnector(queueSize, b);
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);
if (b.usePAM) {
setupPam(b, contexts);
}
addServlet("jmx", "/jmx", JMXJsonServlet.class);
addServlet("conf", "/conf", ConfServlet.class);
addServlet("stacks", "/stacks", StackServlet.class);
addServlet("conflog", "/conflog", Log4j2ConfiguratorServlet.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.server.Connector in project elastic-core-maven by OrdinaryDude.
the class Peers method shutdown.
public static void shutdown() {
if (Init.peerServer != null) {
try {
Init.peerServer.stop();
if (enablePeerUPnP) {
Connector[] peerConnectors = Init.peerServer.getConnectors();
for (Connector peerConnector : peerConnectors) {
if (peerConnector instanceof ServerConnector)
UPnP.deletePort(((ServerConnector) peerConnector).getPort());
}
}
} catch (Exception e) {
Logger.logShutdownMessage("Failed to stop peer server", e);
}
}
ThreadPool.shutdownExecutor("sendingService", sendingService, 2);
ThreadPool.shutdownExecutor("peersService", peersService, 5);
}
use of org.eclipse.jetty.server.Connector in project cxf by apache.
the class JettyHTTPServerEngineFactoryTest method testMakeSureJetty9ConnectorConfigured.
@Test
public void testMakeSureJetty9ConnectorConfigured() throws Exception {
URL config = getClass().getResource("server-engine-factory-jetty9-connector.xml");
bus = new SpringBusFactory().createBus(config, true);
JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
assertNotNull("EngineFactory is not configured.", factory);
JettyHTTPServerEngine engine = null;
engine = factory.createJettyHTTPServerEngine(1234, "http");
assertNotNull("Engine is not available.", engine);
assertEquals(1234, engine.getPort());
assertEquals("Not http", "http", engine.getProtocol());
Connector connector = engine.getConnector();
Collection<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
assertEquals("Has one HttpConnectionFactory", 1, connectionFactories.size());
ConnectionFactory connectionFactory = connectionFactories.iterator().next();
assertTrue(connectionFactory instanceof HttpConnectionFactory);
HttpConfiguration httpConfiguration = ((HttpConnectionFactory) connectionFactory).getHttpConfiguration();
assertEquals("Has one ForwardedRequestCustomizer", 1, httpConfiguration.getCustomizers().size());
assertTrue(httpConfiguration.getCustomizers().iterator().next() instanceof org.eclipse.jetty.server.ForwardedRequestCustomizer);
}
use of org.eclipse.jetty.server.Connector in project scheduling by ow2-proactive.
the class JettyStarter method createHttpServer.
public Server createHttpServer(int httpPort, int httpsPort, boolean httpsEnabled, boolean redirectHttpToHttps) {
int maxThreads = 100;
if (WebProperties.WEB_MAX_THREADS.isSet()) {
maxThreads = WebProperties.WEB_MAX_THREADS.getValueAsInt();
}
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads);
Server server = new Server(threadPool);
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setSendDateHeader(false);
httpConfiguration.setSendServerVersion(false);
Connector[] connectors;
if (httpsEnabled) {
SslContextFactory sslContextFactory = new SslContextFactory();
String httpsKeystore = WebProperties.WEB_HTTPS_KEYSTORE.getValueAsStringOrNull();
String httpsKeystorePassword = WebProperties.WEB_HTTPS_KEYSTORE_PASSWORD.getValueAsStringOrNull();
checkPropertyNotNull(WebProperties.WEB_HTTPS_KEYSTORE.getKey(), httpsKeystore);
checkPropertyNotNull(WebProperties.WEB_HTTPS_KEYSTORE_PASSWORD.getKey(), httpsKeystorePassword);
sslContextFactory.setKeyStorePath(absolutePathOrRelativeToSchedulerHome(httpsKeystore));
sslContextFactory.setKeyStorePassword(httpsKeystorePassword);
if (WebProperties.WEB_HTTPS_TRUSTSTORE.isSet() && WebProperties.WEB_HTTPS_TRUSTSTORE_PASSWORD.isSet()) {
String httpsTrustStore = WebProperties.WEB_HTTPS_TRUSTSTORE.getValueAsString();
String httpsTrustStorePassword = WebProperties.WEB_HTTPS_TRUSTSTORE_PASSWORD.getValueAsString();
sslContextFactory.setTrustStorePath(httpsTrustStore);
sslContextFactory.setTrustStorePassword(httpsTrustStorePassword);
}
HttpConfiguration secureHttpConfiguration = new HttpConfiguration(httpConfiguration);
secureHttpConfiguration.addCustomizer(new SecureRequestCustomizer());
secureHttpConfiguration.setSecurePort(httpsPort);
secureHttpConfiguration.setSecureScheme("https");
secureHttpConfiguration.setSendDateHeader(false);
secureHttpConfiguration.setSendServerVersion(false);
// Connector to listen for HTTPS requests
ServerConnector httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString()), new HttpConnectionFactory(secureHttpConfiguration));
httpsConnector.setName(HTTPS_CONNECTOR_NAME);
httpsConnector.setPort(httpsPort);
if (redirectHttpToHttps) {
// The next two settings allow !403 errors to be redirected to HTTPS
httpConfiguration.setSecureScheme("https");
httpConfiguration.setSecurePort(httpsPort);
// Connector to listen for HTTP requests that are redirected to HTTPS
ServerConnector httpConnector = createHttpConnector(server, httpConfiguration, httpPort);
connectors = new Connector[] { httpConnector, httpsConnector };
} else {
connectors = new Connector[] { httpsConnector };
}
} else {
ServerConnector httpConnector = createHttpConnector(server, httpConfiguration, httpPort);
connectors = new Connector[] { httpConnector };
}
server.setConnectors(connectors);
return server;
}
use of org.eclipse.jetty.server.Connector in project jetty-bootstrap by teknux-org.
the class JettyBootstrap method createConnectors.
/**
* Creates and returns the necessary {@link ServerConnector} based on the given {@link IJettyConfiguration}.
*
* @param iJettyConfiguration
* Jetty Configuration
* @param server
* the server to
* @return Connector[]
* @throws JettyBootstrapException
*/
protected Connector[] createConnectors(IJettyConfiguration iJettyConfiguration, Server server) throws JettyBootstrapException {
LOG.trace("Creating Jetty Connectors...");
List<Connector> connectors = new ArrayList<>();
if (iJettyConfiguration.hasJettyConnector(JettyConnector.HTTP)) {
LOG.trace("Adding HTTP Connector...");
ServerConnector serverConnector;
if (iJettyConfiguration.hasJettyConnector(JettyConnector.HTTPS)) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setSecurePort(iJettyConfiguration.getSslPort());
httpConfiguration.setSecureScheme(HttpScheme.HTTPS.asString());
httpConfiguration.setIdleTimeout(iJettyConfiguration.getIdleTimeout());
httpConfiguration.setBlockingTimeout(iJettyConfiguration.getBlockingTimeout());
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfiguration);
serverConnector = new ServerConnector(server, httpConnectionFactory);
} else {
serverConnector = new ServerConnector(server);
serverConnector.getConnectionFactories().stream().filter(HttpConnectionFactory.class::isInstance).map(HttpConnectionFactory.class::cast).forEach(httpConnectionFactory -> httpConnectionFactory.getHttpConfiguration().setBlockingTimeout(iJettyConfiguration.getBlockingTimeout()));
}
serverConnector.setIdleTimeout(iJettyConfiguration.getIdleTimeout());
serverConnector.setHost(iJettyConfiguration.getHost());
serverConnector.setPort(iJettyConfiguration.getPort());
connectors.add(serverConnector);
}
if (iJettyConfiguration.hasJettyConnector(JettyConnector.HTTPS)) {
LOG.trace("Adding HTTPS Connector...");
SslContextFactory sslContextFactory = new SslContextFactory();
if (iJettyConfiguration.getSslKeyStore() != null) {
// Use keyStore object if available
sslContextFactory.setKeyStore(iJettyConfiguration.getSslKeyStore());
} else if (iJettyConfiguration.getSslPrivateKeyPath() != null && !iJettyConfiguration.getSslPrivateKeyPath().isEmpty() && iJettyConfiguration.getSslCertificatePath() != null && !iJettyConfiguration.getSslCertificatePath().isEmpty()) {
// Use private key and certificate if available
JettyKeystoreConvertorBuilder jettyKeystoreConvertorBuilder = new JettyKeystoreConvertorBuilder();
try {
File sslPrivateKeyFile = new File(iJettyConfiguration.getSslPrivateKeyPath());
if (!sslPrivateKeyFile.exists() || !sslPrivateKeyFile.canRead()) {
throw new JettyBootstrapException("Private key not exists or unreadable");
}
File sslCertificateFile = new File(iJettyConfiguration.getSslCertificatePath());
if (!sslCertificateFile.exists() || !sslCertificateFile.canRead()) {
throw new JettyBootstrapException("Certificate not exists or unreadable");
}
try (InputStream sslPrivateKeyInputStream = new FileInputStream(sslPrivateKeyFile);
InputStream sslCertificateInputStream = new FileInputStream(sslCertificateFile)) {
switch(iJettyConfiguration.getSslCertificateFormat()) {
case PKCS8:
jettyKeystoreConvertorBuilder.setCertificateFromPKCS8(sslCertificateInputStream);
break;
case PKCS12:
jettyKeystoreConvertorBuilder.setCertificateFromPKCS12(sslCertificateInputStream, iJettyConfiguration.getSslCertificatePassword());
break;
case UNKNOWN:
throw new JettyBootstrapException("Unknown Certificate Format");
default:
throw new JettyBootstrapException("Certificate Format not setted");
}
switch(iJettyConfiguration.getSslPrivateKeyFormat()) {
case PKCS8:
jettyKeystoreConvertorBuilder.setPrivateKeyFromPKCS8(sslPrivateKeyInputStream);
break;
case PKCS12:
jettyKeystoreConvertorBuilder.setPrivateKeyFromPKCS12(sslPrivateKeyInputStream, iJettyConfiguration.getSslPrivateKeyPassword());
break;
case UNKNOWN:
throw new JettyBootstrapException("Unknown Private key Format");
default:
throw new JettyBootstrapException("Private key Format not setted");
}
}
KeyStore keyStore = jettyKeystoreConvertorBuilder.build(iJettyConfiguration.getSslKeyStoreAlias(), iJettyConfiguration.getSslKeyStorePassword());
sslContextFactory.setKeyStore(keyStore);
} catch (JettyKeystoreException | IOException e) {
throw new JettyBootstrapException("Can not load SSL private key or SSL certificate", e);
}
} else {
// Use keystore path
sslContextFactory.setKeyStorePath(iJettyConfiguration.getSslKeyStorePath());
}
sslContextFactory.setKeyStorePassword(iJettyConfiguration.getSslKeyStorePassword());
ServerConnector serverConnector = new ServerConnector(server, sslContextFactory);
serverConnector.setIdleTimeout(iJettyConfiguration.getIdleTimeout());
serverConnector.setHost(iJettyConfiguration.getHost());
serverConnector.setPort(iJettyConfiguration.getSslPort());
connectors.add(serverConnector);
}
return connectors.toArray(new Connector[connectors.size()]);
}
Aggregations