Search in sources :

Example 1 with RedirectionServlet

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);
}
Also used : RedirectionServlet(jmri.web.servlet.RedirectionServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

RedirectionServlet (jmri.web.servlet.RedirectionServlet)1 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1