use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project pulsar by yahoo.
the class WebService method start.
public void start() throws PulsarServerException {
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(WebService.HANDLER_REQUEST_LOG_TZ);
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
log.info("Web Service started at {}", pulsar.getWebServiceAddress());
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project gitiles by GerritCodeReview.
the class DevServer method handler.
private Handler handler() throws IOException {
ContextHandlerCollection handlers = new ContextHandlerCollection();
handlers.addHandler(staticHandler());
handlers.addHandler(appHandler());
return handlers;
}
use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project JMRI by JMRI.
the class WebServer method start.
/**
* Start the web server.
*/
@Override
public void start() {
if (!server.isRunning()) {
ServerConnector connector = new ServerConnector(server);
// 5 minutes
connector.setIdleTimeout(5 * 60 * 1000);
connector.setSoLingerTime(-1);
connector.setPort(preferences.getPort());
server.setConnectors(new Connector[] { connector });
server.setHandler(new ContextHandlerCollection());
// Load all path handlers
ServiceLoader.load(WebServerConfiguration.class).forEach((configuration) -> {
configuration.getFilePaths().entrySet().forEach((resource) -> {
this.registerResource(resource.getKey(), resource.getValue());
});
configuration.getRedirectedPaths().entrySet().forEach((redirection) -> {
this.registerRedirection(redirection.getKey(), redirection.getValue());
});
configuration.getForbiddenPaths().forEach((denial) -> {
this.registerDenial(denial);
});
});
// Load all classes that provide the HttpServlet service.
ServiceLoader.load(HttpServlet.class).forEach((servlet) -> {
this.registerServlet(servlet.getClass(), servlet);
});
server.addLifeCycleListener(this);
Thread serverThread = new ServerThread(server);
// NOI18N
serverThread.setName("WebServer");
serverThread.start();
}
}
use of org.eclipse.jetty.server.handler.ContextHandlerCollection in project JMRI by JMRI.
the class WebServer method registerRedirection.
/**
* Register a URL pattern to be redirected to another resource.
*
* @param urlPattern the pattern to be redirected
* @param redirection the path to which the pattern is redirected
* @throws IllegalArgumentException if urlPattern is already registered for
* any other purpose
*/
public void registerRedirection(String urlPattern, String redirection) throws IllegalArgumentException {
Registration registered = this.registeredUrls.get(urlPattern);
if (registered != null && registered != Registration.REDIRECTION) {
throw new IllegalArgumentException("\"" + urlPattern + "\" registered to " + registered);
}
this.registeredUrls.put(urlPattern, Registration.REDIRECTION);
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
servletContext.setContextPath(urlPattern);
RedirectionServlet servlet = new RedirectionServlet(urlPattern, redirection);
// NOI18N
servletContext.addServlet(new ServletHolder(servlet), "");
((ContextHandlerCollection) this.server.getHandler()).addHandler(servletContext);
}
Aggregations