'jsf - get bookmarkable URL in filter

How can i retrieve the bookmarkable URL, respecting rewritten rules using ViewHandler.getBookmarkableURL(...) inside a @WebFilter to redirect the user to the rewritten login page URL.

Is there an alternate function to get a bookmarkable URL without FacesContext?

Simplified example

The page /sites/user/login.xhtml is rewritten to just /Login using OCPSoft rewrite library but in following filter i dont know how to do this since i dont have access to FacesContext.

The real example has additional querystring params that also contribute to the rewritten URL

@WebFilter(filterName = "UserFilter", urlPatterns =
{
    "/sites/user/account.xhtml"
}, dispatcherTypes =
{
    DispatcherType.FORWARD, DispatcherType.REQUEST, DispatcherType.ERROR
})
public class UserFilter extends HttpFilter
{
    @Override
    public void doFilter(final HttpServletRequest request, final HttpServletResponse response,
        final HttpSession session, final FilterChain chain) throws ServletException, IOException
    {
        if (isLoggedIn())
            chain.doFilter(request, response);
        else
            response.sendRedirect(request.getContextPath() + "/sites/user/login.xhtml");
    }
}   


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source