in src/main/java/org/apache/sling/engine/impl/filter/AbstractSlingFilterChain.java [49:98]
public void doFilter(final ServletRequest request, final ServletResponse response)
throws ServletException, IOException {
final int filterIdx = ++this.current;
final long start = System.nanoTime();
if (filterIdx > this.filters.length) {
// this happens when the whole filter chain has been executed, and a filter in that chain,
// for some (bad) reason, calls doFilter yet another time.
throw new IllegalStateException("doFilter should not be called more than once");
}
// the previous filter may have wrapped non-Sling request and response
// wrappers (e.g. WebCastellum does this), so we have to make
// sure the request and response are Sling types again
SlingJakartaHttpServletRequest slingRequest = toSlingRequest(request);
SlingJakartaHttpServletResponse slingResponse = toSlingResponse(response);
try {
if (this.current < this.filters.length) {
// continue filtering with the next filter
FilterHandle filter = this.filters[this.current];
if (filter.select(slingRequest)) {
LOG.debug("{} got selected for this request", filter);
trackFilter(slingRequest, filter);
filter.getFilter().doFilter(slingRequest, slingResponse, this);
} else {
LOG.debug("{} was not selected for this request", filter);
if (this.current == this.filters.length - 1) {
this.render(slingRequest, slingResponse);
} else {
doFilter(slingRequest, slingResponse);
}
}
} else {
this.render(slingRequest, slingResponse);
}
} finally {
if (filterIdx < times.length) {
times[filterIdx] = (System.nanoTime() - start) / 1000;
if (filterIdx == 0) {
consolidateFilterTimings(slingRequest);
}
}
}
}