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);
}
use of org.eclipse.jetty.server.handler.ContextHandlerCollection 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");
}
}
Aggregations