public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
      throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    // prepare the request no matter what - this ensures that the proper character encoding
    // is used before invoking the mapper (see WW-9127)
    DispatcherUtils du = DispatcherUtils.getInstance();
    du.prepare(request, response);

    ServletContext servletContext = filterConfig.getServletContext();
    try {
      request = du.wrapRequest(request, servletContext);
    } catch (IOException e) {
      String message = "Could not wrap servlet request with MultipartRequestWrapper!";
      LOG.error(message, e);
      throw new ServletException(message, e);
    }

    try {

      Integer count = (Integer) request.getAttribute(COUNTER);
      if (count == null) {
        count = new Integer(1);
      } else {
        count = new Integer(count.intValue() + 1);
      }
      request.setAttribute(COUNTER, count);

      chain.doFilter(request, response);
    } finally {

      int counterVal = ((Integer) request.getAttribute(COUNTER)).intValue();
      counterVal -= 1;
      request.setAttribute(COUNTER, new Integer(counterVal));

      cleanUp(request);
    }
  }
 public void init(FilterConfig filterConfig) throws ServletException {
   this.filterConfig = filterConfig;
   DispatcherUtils.initialize(filterConfig.getServletContext());
 }