  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    long start = System.currentTimeMillis();
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    final GenericResponseWrapper wrapper = new GenericResponseWrapper(httpResponse, outstr);
    chain.doFilter(request, wrapper);
    wrapper.flushBuffer();
    final byte[] data = outstr.toByteArray();
    String requestURI = httpRequest.getRequestURI();
    if (requestURI.matches(".*\\.(html|js|css|jpg|png|gif)$")
        && httpResponse.getStatus() == HttpServletResponse.SC_OK) {
      File cacheFile = new File(cacheDir, "/" + httpRequest.getServerName() + requestURI);
      new CacheThread(cacheFile, data).start();
    }
    response.getOutputStream().write(data);
    long end = System.currentTimeMillis();
    RequestProcessTime rpt = new RequestProcessTime();
    rpt.setStart(start);
    rpt.setEnd(end);
    rpt.setTime(end - start);
    rpt.setMethod(httpRequest.getMethod());
    rpt.setRequest(httpRequest.getRequestURL().toString());
    rpt.setQuery(httpRequest.getQueryString());
    mongdoDb.createObject("RequestProcessTime", rpt);
  }

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    long start = System.currentTimeMillis();
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    final GenericResponseWrapper wrapper = new GenericResponseWrapper(httpResponse, outstr);
    chain.doFilter(request, wrapper);
    wrapper.flushBuffer();
    final byte[] data = outstr.toByteArray();
    String requestURI = httpRequest.getRequestURI();
    int status = httpResponse.getStatus();
    if (requestURI.matches(".*\\.(html|js|css|jpg|png|gif)$")
        && (status == 0 || status == HttpServletResponse.SC_OK)) {
      File cacheFile = new File(cacheDir, "/" + httpRequest.getServerName() + requestURI);
      new CacheThread(cacheFile, data).start();
    }
    response.getOutputStream().write(data);
    long end = System.currentTimeMillis();
    RequestProcessTime rpt = new RequestProcessTime();
    rpt.setStart(start);
    rpt.setEnd(end);
    rpt.setTime(end - start);
    rpt.setMethod(httpRequest.getMethod());
    rpt.setRequest(httpRequest.getRequestURL().toString());
    rpt.setQuery(httpRequest.getQueryString());
    mongdoDb.createObject("RequestProcessTime", rpt);
  }
