@Test public void doFilter() throws Exception { LbHttpsRedirectFilter filter = new LbHttpsRedirectFilter(); filter.init(null); HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); FilterChain chain = mock(FilterChain.class); when(request.getHeader("X-Forwarded-Proto")) .thenReturn("http"); when(request.getRequestURL()) .thenReturn(new StringBuffer("http: filter.doFilter(request, response, chain); verify(response).sendRedirect("https: filter.destroy(); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse && "http".equals(((HttpServletRequest)request).getHeader("X-Forwarded-Proto"))) { String url = ((HttpServletRequest)request).getRequestURL().toString(); HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.sendRedirect(url.replace("http: } else { filterChain.doFilter(request, response); } }
LbHttpsRedirectFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse && "http".equals(((HttpServletRequest)request).getHeader("X-Forwarded-Proto"))) { String url = ((HttpServletRequest)request).getRequestURL().toString(); HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.sendRedirect(url.replace("http: } else { filterChain.doFilter(request, response); } } }
LbHttpsRedirectFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse && "http".equals(((HttpServletRequest)request).getHeader("X-Forwarded-Proto"))) { String url = ((HttpServletRequest)request).getRequestURL().toString(); HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.sendRedirect(url.replace("http: } else { filterChain.doFilter(request, response); } }  }
LbHttpsRedirectFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse && "http".equals(((HttpServletRequest)request).getHeader("X-Forwarded-Proto"))) { String url = ((HttpServletRequest)request).getRequestURL().toString(); HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.sendRedirect(url.replace("http: } else { filterChain.doFilter(request, response); } }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain); @Override void destroy(); }
LbHttpsRedirectFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse && "http".equals(((HttpServletRequest)request).getHeader("X-Forwarded-Proto"))) { String url = ((HttpServletRequest)request).getRequestURL().toString(); HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.sendRedirect(url.replace("http: } else { filterChain.doFilter(request, response); } }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain); @Override void destroy();  }