use of org.eclipse.jetty.server.handler.HandlerList in project scheduling by ow2-proactive.
the class JettyStarter method deployWebApplications.
public List<String> deployWebApplications(String rmUrl, String schedulerUrl) {
initializeRestProperties();
setSystemPropertyIfNotDefined("rm.url", rmUrl);
setSystemPropertyIfNotDefined("scheduler.url", schedulerUrl);
System.setProperty(CentralPAPropertyRepository.JAVAX_XML_TRANSFORM_TRANSFORMERFACTORY.getName(), DEFAULT_XML_TRANSFORMER);
if (WebProperties.WEB_DEPLOY.getValueAsBoolean()) {
logger.info("Starting the web applications...");
int httpPort = getJettyHttpPort();
int httpsPort = 443;
if (WebProperties.WEB_HTTPS_PORT.isSet()) {
httpsPort = WebProperties.WEB_HTTPS_PORT.getValueAsInt();
}
boolean httpsEnabled = WebProperties.WEB_HTTPS.getValueAsBoolean();
boolean redirectHttpToHttps = WebProperties.WEB_REDIRECT_HTTP_TO_HTTPS.getValueAsBoolean();
int restPort = httpPort;
String httpProtocol;
String[] defaultVirtualHost;
String[] httpVirtualHost = new String[] { "@" + HTTP_CONNECTOR_NAME };
if (httpsEnabled) {
httpProtocol = "https";
defaultVirtualHost = new String[] { "@" + HTTPS_CONNECTOR_NAME };
restPort = httpsPort;
} else {
defaultVirtualHost = httpVirtualHost;
httpProtocol = "http";
}
Server server = createHttpServer(httpPort, httpsPort, httpsEnabled, redirectHttpToHttps);
server.setStopAtShutdown(true);
HandlerList topLevelHandlerList = new HandlerList();
if (httpsEnabled && redirectHttpToHttps) {
ContextHandler redirectHandler = new ContextHandler();
redirectHandler.setContextPath("/");
redirectHandler.setHandler(new SecuredRedirectHandler());
redirectHandler.setVirtualHosts(httpVirtualHost);
topLevelHandlerList.addHandler(redirectHandler);
}
topLevelHandlerList.addHandler(createSecurityHeadersHandler());
if (WebProperties.JETTY_LOG_FILE.isSet()) {
String pathToJettyLogFile = FileStorageSupportFactory.relativeToHomeIfNotAbsolute(WebProperties.JETTY_LOG_FILE.getValueAsString());
File jettyLogFile = new File(pathToJettyLogFile);
if (!jettyLogFile.getParentFile().exists() && !jettyLogFile.getParentFile().mkdirs()) {
logger.error("Could not create jetty log file in: " + WebProperties.JETTY_LOG_FILE.getValueAsString());
} else {
NCSARequestLog requestLog = new NCSARequestLog(pathToJettyLogFile);
requestLog.setAppend(true);
requestLog.setExtended(false);
requestLog.setLogTimeZone("GMT");
requestLog.setLogLatency(true);
requestLog.setRetainDays(WebProperties.JETTY_LOG_RETAIN_DAYS.getValueAsInt());
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
topLevelHandlerList.addHandler(requestLogHandler);
}
}
RewriteHandler rewriteHandler = null;
HandlerList contextHandlerList = null;
if (WebProperties.WEB_PCA_PROXY_REWRITE_ENABLED.getValueAsBoolean()) {
rewriteHandler = new RewriteHandler();
PCAProxyRule proxyRule = new PCAProxyRule();
rewriteHandler.addRule(proxyRule);
rewriteHandler.setRewriteRequestURI(true);
rewriteHandler.setRewritePathInfo(false);
rewriteHandler.setOriginalPathAttribute(PCAProxyRule.originalPathAttribute);
rewriteHandler.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
contextHandlerList = new HandlerList();
} else {
contextHandlerList = topLevelHandlerList;
}
addWarsToHandlerList(contextHandlerList, defaultVirtualHost);
if (WebProperties.WEB_PCA_PROXY_REWRITE_ENABLED.getValueAsBoolean()) {
rewriteHandler.setHandler(contextHandlerList);
topLevelHandlerList.addHandler(rewriteHandler);
}
server.setHandler(topLevelHandlerList);
if (logger.isDebugEnabled()) {
server.setDumpAfterStart(true);
}
String schedulerHost = ProActiveInet.getInstance().getHostname();
return startServer(server, schedulerHost, restPort, httpProtocol);
}
return new ArrayList<>();
}
use of org.eclipse.jetty.server.handler.HandlerList in project athenz by yahoo.
the class SSLUtilsTest method createHttpsJettyServer.
private static JettyServer createHttpsJettyServer(boolean clientAuth) throws IOException {
Server server = new Server();
HttpConfiguration https_config = new HttpConfiguration();
https_config.setSecureScheme("https");
int port;
try (ServerSocket socket = new ServerSocket(0)) {
port = socket.getLocalPort();
}
https_config.setSecurePort(port);
https_config.setOutputBufferSize(32768);
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
File keystoreFile = new File(DEFAULT_SERVER_KEY_STORE);
if (!keystoreFile.exists()) {
throw new FileNotFoundException();
}
String trustStorePath = DEFAULT_CA_TRUST_STORE;
File trustStoreFile = new File(trustStorePath);
if (!trustStoreFile.exists()) {
throw new FileNotFoundException();
}
sslContextFactory.setEndpointIdentificationAlgorithm(null);
sslContextFactory.setTrustStorePath(trustStorePath);
sslContextFactory.setTrustStoreType(DEFAULT_SSL_STORE_TYPE);
sslContextFactory.setTrustStorePassword(DEFAULT_CERT_PWD);
sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
sslContextFactory.setKeyStoreType(DEFAULT_SSL_STORE_TYPE);
sslContextFactory.setKeyStorePassword(DEFAULT_CERT_PWD);
sslContextFactory.setProtocol(DEFAULT_SSL_PROTOCOL);
sslContextFactory.setNeedClientAuth(clientAuth);
ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
https.setPort(port);
https.setIdleTimeout(500000);
server.setConnectors(new Connector[] { https });
HandlerList handlers = new HandlerList();
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newResource("."));
handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
server.setHandler(handlers);
return new JettyServer(server, port);
}
use of org.eclipse.jetty.server.handler.HandlerList in project NMEAParser by tvesalainen.
the class CommandLine method start.
private void start() throws IOException, InterruptedException, JAXBException, Exception {
config("starting NMEA Server");
Path configfile = getArgument("configuration file");
Config config = new Config(configfile);
String address = config.getNmeaMulticastAddress();
int nmeaPort = config.getNmeaMulticastPort();
int httpPort = config.getHttpPort();
config("NMEA Multicast Address=%s", address);
config("NMEA Multicast Port=%s", nmeaPort);
config("HTTP Port=%s", httpPort);
CachedScheduledThreadPool executor = new CachedScheduledThreadPool(64);
config("ThreadPool started %s", executor);
NMEAService nmeaService = new NMEAService(address, nmeaPort, executor);
PropertyServer propertyServer = new PropertyServer(Clock.systemDefaultZone(), config, executor);
nmeaService.addNMEAObserver(propertyServer);
nmeaService.start();
config("NMEA Service started");
JavaUtilLog log = new JavaUtilLog();
// make jetty use java.util.logger
Log.setLog(log);
Server server = new Server(httpPort);
HandlerList handlers = new HandlerList();
ServletContextHandler context = new ServletContextHandler();
context.addServlet(ResourceServlet.class, "/");
ServletHolder holder = new ServletHolder(SseServlet.class);
holder.setAsyncSupported(true);
context.addServlet(holder, "/sse");
context.addServlet(ResourceServlet.class, "*.js");
context.addServlet(ResourceServlet.class, "*.css");
context.addServlet(ResourceServlet.class, "*.gif");
context.addServlet(ResourceServlet.class, "*.png");
context.addServlet(ResourceServlet.class, "*.ico");
context.addServlet(PrefsServlet.class, "/prefs");
context.addServlet(I18nServlet.class, "/i18n");
SessionHandler sessionHandler = new SessionHandler();
context.setSessionHandler(sessionHandler);
handlers.addHandler(context);
server.setHandler(handlers);
server.setSessionIdManager(new DefaultSessionIdManager(server));
ServletContext servletContext = context.getServletContext().getContext("/sse");
servletContext.setAttribute(PropertyServer.class.getName(), propertyServer);
server.start();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
use of org.eclipse.jetty.server.handler.HandlerList in project cia by Hack23.
the class CitizenIntelligenceAgencyServer method init.
/**
* Inits the.
*
* @throws Exception
* the exception
*/
public final void init() throws Exception {
initialised = true;
server = new Server();
Security.addProvider(new BouncyCastleProvider());
// Setup JMX
final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
final org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
final HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(28443);
final HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStoreType("JKS");
sslContextFactory.setKeyStorePath("target/keystore.jks");
sslContextFactory.setTrustStorePath("target/keystore.jks");
sslContextFactory.setKeyStorePassword("changeit");
sslContextFactory.setTrustStorePassword("changeit");
sslContextFactory.setKeyManagerPassword("changeit");
sslContextFactory.setCertAlias("jetty");
sslContextFactory.setIncludeCipherSuites("TLS_DHE_RSA.*", "TLS_ECDHE.*");
sslContextFactory.setExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");
sslContextFactory.setIncludeProtocols("TLSv1.2");
final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config), new HTTP2CServerConnectionFactory(https_config));
sslConnector.setPort(PORT);
server.setConnectors(new ServerConnector[] { sslConnector });
final WebAppContext handler = new WebAppContext("src/main/webapp", "/");
handler.setExtraClasspath("target/classes");
handler.setParentLoaderPriority(true);
handler.setConfigurationDiscovered(true);
handler.setClassLoader(Thread.currentThread().getContextClassLoader());
final HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
server.setHandler(handlers);
}
use of org.eclipse.jetty.server.handler.HandlerList in project selenium_java by sergueik.
the class RunScriptTest method beforeSuiteMethod.
@BeforeSuite
public void beforeSuiteMethod() throws Exception {
((StdErrLog) Log.getRootLogger()).setLevel(StdErrLog.LEVEL_OFF);
webServer = new Server(new QueuedThreadPool(5));
ServerConnector connector = new ServerConnector(webServer, new HttpConnectionFactory());
connector.setPort(8080);
webServer.addConnector(connector);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("src/test/webapp");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
webServer.setHandler(handlers);
webServer.start();
driver = new FirefoxDriver();
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
wait = new WebDriverWait(driver, flexibleWait);
wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
hashesFinderScript = getScriptContent("hashesFinder.js");
resultFinderScript = getScriptContent("resultFinder.js");
}
Aggregations