-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Brad,

On 2/13/2009 7:34 PM, Brad Whitaker wrote:
> Is there a logger that can emit information about when servlet filters are
> invoked?

Not a logger per-se, but there is an internal event fired and can
presumably be listened-to. See the source for
java/org/apache/catalina/core/ApplicationFilterChain.java, specifically
the internalDoFilter method. You can see these two events reported:

                support.fireInstanceEvent(InstanceEvent.BEFORE_FILTER_EVENT,
                                          filter, request, response);

...

                support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
                                          filter, request, response);


I'm not sure what the best way is to listen to these events.
org.apache.catalina.util.InstanceSupport is the class for the 'support'
reference above. That class has methods for registering event listeners,
but I'm not sure what the best way is to get the instance of
InstanceSupport that is being used by Tomcat. JMX might work to grab
that object from Tomcat.

> I have multiple filters
> that have been provided by 3rd party libraries and it is very difficult to
> know when they are invoked, and in what order.

They should be invoked in the order in which they are declared in
web.xml. Is this not the behavior you are observing? What version of
Tomcat are you running?

> I'd primarily
> like to know when doFilter() is invoked (along with the name of the filter).
> I think this would be enough to follow the chains.

You could write a trivial filter that does something like this:

public class OrderingFilter
 implements Filter
{
   private String _name;
   public void init(FilterConfig config)
   {
      _name = config.getInitParameter("name");
   }

   public void doFilter(ServletRequest request,
                        ServletResponse response,
                        FilterChain chain)
      throws IOException, ServletException
   {
       System.out.println("Running " + _name);

       chain.doFilter(request, response);

       System.out.println("Finished running " + _name);
   }
}

Then, configure this filter to run in between every filter you have
configured. Something like this:

Filter A
OrderingFilter[name='after A']
Filter B
OrderingFilter[name='after B']
Filter C
OrderingFilter[name='after C']
Filter D
OrderingFilter[name='after D']
Filter E
OrderingFilter[name='after E']
...

This gives you a crude yet non-invasive debugging mechanism. Just make
sure that you have all your url-mappings set up to mirror those of the
original filters.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmZ5QgACgkQ9CaO5/Lv0PDVFwCfYh9Mf0R6xUhi8gorM3sWnBgA
D64AoL7sBsxNRh8MNSW09vfoJ70BmjJK
=3fLv
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to