code: public void doFilter(ServletRequest request,
                           ServletResponse response,
                           FilterChain chain)
  	throws IOException, ServletException
      {
          HttpServletRequest  srequest  = (HttpServletRequest)request;
          HttpServletResponse sresponse = (HttpServletResponse)response;
          Request requestWrapper=null;
          Response responseWrapper=null;
          boolean root_filter=false;
          
  
          // Do we need a root wrapper?
          ThreadState state = state();
          if (_unwrappedDispatchSupported || LazyList.size(_requestAttributeListeners)>0 )
          {
              if (srequest instanceof ServletHttpRequest)
              {
                  request=state.rootRequest=requestWrapper=new Request(srequest);
                  response=state.rootResponse=responseWrapper=new Response(sresponse);
                  root_filter=true;
              }
              else
              {
                  requestWrapper=state.rootRequest;
                  responseWrapper=state.rootResponse;
              }
          }
          
          // Is this the first time this request has been in this _context?
          boolean first_in_context=root_filter ||
          	requestWrapper!=null && 
          	requestWrapper.getRequest()!=null && requestWrapper.getRequest() instanceof Dispatcher.DispatcherRequest &&
          	((Dispatcher.DispatcherRequest)requestWrapper.getRequest()).crossContext();
          
          if (first_in_context)
          {
              requestInitialized(request);
              
              if (requestWrapper!=null && LazyList.size(_requestAttributeListeners)>0)
                  requestWrapper.addContextFilter(this);
          }
          
          // setup dispatch
          boolean dispatch=false;
          if (_unwrappedDispatchSupported && state.dispatchRequest!=null)
          {
              dispatch=true;
              requestWrapper.pushWrapper(state.dispatchRequest);
              responseWrapper.pushWrapper(state.dispatchResponse);
              state.dispatchRequest=null;
              state.dispatchResponse=null;
          }
          
          try
          {
              chain.doFilter(request, response);   
          }
          finally
          {
              if (first_in_context)
              {
                  requestDestroyed(request);
                  if (requestWrapper!=null && LazyList.size(_requestAttributeListeners)>0)
                      requestWrapper.delContextFilter(this);
              }
              
              if (root_filter)
                  state.clear();
              
              if (dispatch)
              {
                  requestWrapper.popWrapper();
                  responseWrapper.popWrapper();
              }
          }
      }
docs: /* ------------------------------------------------------------