Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to Determine order of Servlet Filters in Spring application

A short Groovy script that you can use to filter out the noise from a stack trace to see what order the servlet filters are actually configured with.

A simple way to do this is throw a RuntimeException from a controller, hit that URL, and copy and paste the stack trace into the script below.

x is the stack trace
x.split('\n').findAll { it =~ /doFilter/ }
.findAll { !(it =~ /ApplicationFilterChain/)}
.findAll { !(it =~ /OncePerRequestFilter/)}
.findAll { !(it =~ /FilterChainProxy/)}
.collect {
def r
it.eachMatch(/at (.*)\.doFilter/) { match -> r = match[1]}
return r
}.each { println it }
println 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment