class HTTPSFilter extends AbstractFilter {

  private static final Pattern HTTP_REGEX = Pattern.compile("http://");

  @Override
  public void doFilter(ServletRequest servletRequest,
                       ServletResponse servletResponse,
                       FilterChain chain) throws IOException, ServletException {<FILL_FUNCTION_BODY>}

}

    if (servletRequest.isSecure()) {
      chain.doFilter(servletRequest, servletResponse);
    } else {
      HttpServletRequest request = (HttpServletRequest) servletRequest;
      String url = request.getRequestURL().toString();
      String target = HTTP_REGEX.matcher(url).replaceFirst("https://");
      redirect(servletResponse, target);
    }
  
<methods>public final void destroy() ,public final void init(FilterConfig) <variables>