tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brad Whitaker <dbw...@yahoo.com>
Subject Re: filter debugging or logging?
Date Tue, 17 Feb 2009 01:43:50 GMT

Thanks for the response. I wanted to know about the order primarily because I
thought I might be having a problem with <dispatcher> configuration, i.e. I
was concerned that some filters might or might not be firing on ERROR and
REDIRECT. I've done enough debugging at this point to determine this is not
my problem. (My problem seems to be that Tomcat 6 is not sending a redirect
when I invoke HttpServletResponse.sendRedirect(redirectUrl) but I'll put
that in a separate topic.)



Christopher Schultz-2 wrote:
> 
> -----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-----
> 
> 

-- 
View this message in context: http://www.nabble.com/filter-debugging-or-logging--tp22007573p22049002.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Mime
View raw message