001package jmri.web.servlet;
002
003import java.io.IOException;
004import java.util.Properties;
005import javax.servlet.ServletException;
006import javax.servlet.annotation.WebServlet;
007import javax.servlet.http.HttpServlet;
008import javax.servlet.http.HttpServletRequest;
009import javax.servlet.http.HttpServletResponse;
010
011/**
012 * Redirect traffic to another location.
013 *
014 * @author Randall Wood (C) 2016
015 */
016@WebServlet(name = "RedirectionServlet")
017public class RedirectionServlet extends HttpServlet {
018
019    private final Properties redirections = new Properties();
020    // private static final Logger log = LoggerFactory.getLogger(RedirectionServlet.class);
021
022    public RedirectionServlet() {
023        // do nothing
024    }
025
026    public RedirectionServlet(String urlPattern, String redirection) {
027        this.redirections.setProperty(urlPattern, redirection);
028    }
029
030    @Override
031    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
032        response.sendRedirect(redirections.getProperty(request.getContextPath()));
033    }
034
035    @Override
036    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
037        this.doGet(request, response);
038    }
039
040}