use of org.eclipse.jetty.server.handler.HandlerList in project alluxio by Alluxio.
the class WebServer method addHandler.
/**
* Adds a handler.
*
* @param handler the handler to add
*/
public void addHandler(AbstractHandler handler) {
HandlerList handlers = new HandlerList();
handlers.addHandler(handler);
for (Handler h : mServer.getHandlers()) {
handlers.addHandler(h);
}
mServer.setHandler(handlers);
}
use of org.eclipse.jetty.server.handler.HandlerList in project leopard by tanhaichao.
the class WebappDaoImpl method getHandlerList.
protected Handler getHandlerList(List<String> hostList) {
// jettyServer.getWebappService().addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
if (hostList.contains("fshop.leopard.io")) {
if (false) {
return new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/");
}
HandlerList handlerList = new HandlerList();
handlerList.addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
handlerList.addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
try {
handlerList.start();
} catch (Exception e) {
e.printStackTrace();
}
return handlerList;
}
return null;
}
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);
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 handlerList = new HandlerList();
if (httpsEnabled && redirectHttpToHttps) {
ContextHandler redirectHandler = new ContextHandler();
redirectHandler.setContextPath("/");
redirectHandler.setHandler(new SecuredRedirectHandler());
redirectHandler.setVirtualHosts(httpVirtualHost);
handlerList.addHandler(redirectHandler);
}
addWarsToHandlerList(handlerList, defaultVirtualHost);
server.setHandler(handlerList);
String schedulerHost = ProActiveInet.getInstance().getHostname();
return startServer(server, schedulerHost, restPort, httpProtocol);
}
return new ArrayList<>();
}
use of org.eclipse.jetty.server.handler.HandlerList in project scheduling by ow2-proactive.
the class JettyStarter method printDeployedApplications.
private List<String> printDeployedApplications(Server server, String schedulerHost, int restPort, String httpProtocol) {
HandlerList handlerList = (HandlerList) server.getHandler();
ArrayList<String> applicationsUrls = new ArrayList<>();
if (handlerList.getHandlers() != null) {
for (Handler handler : handlerList.getHandlers()) {
if (!(handler instanceof WebAppContext)) {
continue;
}
WebAppContext webAppContext = (WebAppContext) handler;
Throwable startException = webAppContext.getUnavailableException();
if (startException == null) {
if (!"/".equals(webAppContext.getContextPath())) {
String applicationUrl = getApplicationUrl(httpProtocol, schedulerHost, restPort, webAppContext);
applicationsUrls.add(applicationUrl);
logger.info("The web application " + webAppContext.getContextPath() + " created on " + applicationUrl);
}
} else {
logger.warn("Failed to start context " + webAppContext.getContextPath(), startException);
}
}
logger.info("*** Get started at " + httpProtocol + "://" + schedulerHost + ":" + restPort + " ***");
}
return applicationsUrls;
}
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 MalformedURLException, IOException {
Server server = new Server();
HttpConfiguration https_config = new HttpConfiguration();
https_config.setSecureScheme("https");
int port = 0;
try (ServerSocket socket = new ServerSocket(0)) {
port = socket.getLocalPort();
}
https_config.setSecurePort(port);
https_config.setOutputBufferSize(32768);
String keystorePath = DEFAULT_SERVER_KEY_STORE;
SslContextFactory sslContextFactory = new SslContextFactory();
File keystoreFile = new File(keystorePath);
if (!keystoreFile.exists()) {
throw new FileNotFoundException();
}
String trustStorePath = DEFAULT_CA_TRUST_STORE;
File trustStoreFile = new File(trustStorePath);
if (!trustStoreFile.exists()) {
throw new FileNotFoundException();
}
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);
}
Aggregations