* such servlet willing to handle the request could be found.
*/
private Servlet getServletInternal(final AbstractResourceCollector locationUtil,
final SlingHttpServletRequest request,
final ResourceResolver resolver) {
final Servlet scriptServlet = (this.cache != null ? this.cache.get(locationUtil) : null);
if (scriptServlet != null) {
if ( LOGGER.isDebugEnabled() ) {
LOGGER.debug("Using cached servlet {}", RequestUtil.getServletName(scriptServlet));
}
return scriptServlet;
}
final Collection<Resource> candidates = locationUtil.getServlets(resolver);
if (LOGGER.isDebugEnabled()) {
if (candidates.isEmpty()) {
LOGGER.debug("No servlet candidates found");
} else {
LOGGER.debug("Ordered list of servlet candidates follows");
for (Resource candidateResource : candidates) {
LOGGER.debug("Servlet candidate: {}", candidateResource.getPath());
}
}
}
boolean hasOptingServlet = false;
for (final Resource candidateResource : candidates) {
LOGGER.debug("Checking if candidate resource {} adapts to servlet and accepts request", candidateResource
.getPath());
Servlet candidate = this.getServlet(candidateResource);
if (candidate != null) {
final boolean isOptingServlet = candidate instanceof OptingServlet;
boolean servletAcceptsRequest = !isOptingServlet || (request != null && ((OptingServlet) candidate).accepts(request));
if (servletAcceptsRequest) {
if (!hasOptingServlet && !isOptingServlet && this.cache != null) {