use of jmri.web.servlet.RedirectionServlet 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