Redirect to external URL servlet filter
<p>I'm having trouble redirecting the user in servlet filter.</p>

<pre><code>@WebFilter(value = "/*", initParams = { @WebInitParam(name = "applicationClassName", value = "com.sample.Application"),
@WebInitParam(name="filterMappingUrlPattern", value="/*") })
public class CertFilter extends WicketFilter {

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        if(USER_MATCHES_CONDITION){
            httpServletResponse.setHeader("Location", "https://google.com");
            httpServletResponse.sendRedirect("https://google.com");
        }
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }
}
</code></pre>

<p>The request to google.com is done but user is not redirected to there. The request intercepted meaning USER_MATCHES_CONDITION is met at the time when stylesheet is requested. Thus redirection request header is <code>Accept:text/css,*/*;q=0.1</code>. So I get a warning Resource interpreted as Stylesheet but transferred with MIME type text/html. Probably this is the reason why it's not redirecting.</p>

<p>How to intercept random request and redirect it to external url?</p>

<p><strong>EDIT:</strong> Even if I do just like this:</p>

<pre><code>@Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        httpServletResponse.sendRedirect("https://google.com");
        return;
    }
</code></pre>

<p>It does not redirect the user... I'm guessing wicket overrides it somehow.</p>