protected void redirectToLoginPage(HttpServletRequest request, HttpServletResponse response,
            List<Pair<String, String>> queryParams) {
        try {
            StringBuilder pathBuilder = new StringBuilder();
            pathBuilder.append(request.getContextPath());
            pathBuilder.append("/");
            pathBuilder.append(loginPage);

            URLBuilder urlBuilder = new URLBuilder();
            urlBuilder.setScheme(request.getScheme());
            urlBuilder.setHost(request.getServerName());
            urlBuilder.setPort(request.getServerPort());
            urlBuilder.setPath(pathBuilder.toString());

            if (queryParams == null) {
                queryParams = new ArrayList<Pair<String, String>>();
            }

            queryParams.add(new Pair<String, String>("actionUrl", request.getContextPath()
                    + request.getServletPath()));
            urlBuilder.getQueryParams().addAll(queryParams);

            log.debug("Redirecting to login page {}", urlBuilder.buildURL());
            response.sendRedirect(urlBuilder.buildURL());
            return;
        } catch (IOException ex) {
            log.error("Unable to redirect to login page.", ex);
        }
    }