public Servlet resolveServlet(SlingHttpServletRequest request) {
Resource resource = request.getResource();
// start tracking servlet resolution
RequestProgressTracker tracker = request.getRequestProgressTracker();
String timerName = "resolverServlet(" + resource + ")";
tracker.startTimer(timerName);
Servlet servlet = null;
final String type = resource.getResourceType();
if(log.isDebugEnabled()) {
log.debug("resolveServlet called for Resource {}", request.getResource());
}
// first check whether the type of a resource is the absolute
// path of a servlet (or script)
if (type.charAt(0) == '/') {
Resource res = request.getResourceResolver().getResource(type);
if (res != null) {
servlet = res.adaptTo(Servlet.class);
}
if(servlet!=null && log.isDebugEnabled()) {
log.debug("Servlet {} found using absolute resource type {}", RequestUtil.getServletName(servlet), type);
}
}
// the resource type is not absolute, so lets go for the deep search
if (servlet == null) {
ResourceCollector locationUtil = ResourceCollector.create(request);
servlet = getServlet(locationUtil, request, resource);
if(log.isDebugEnabled()) {
log.debug("getServlet returns Servlet {}", RequestUtil.getServletName(servlet));
}
}
// last resort, use the core bundle default servlet
if (servlet == null) {
if(log.isDebugEnabled()) {
log.debug("No specific Servlet found, trying default");
}
servlet = getDefaultServlet();
}
// track servlet resolution termination
if (servlet == null) {
tracker.logTimer(timerName,
"Servlet Resolution failed. See log for details");
} else {
tracker.logTimer(timerName, "Using Servlet {0}",
RequestUtil.getServletName(servlet));
}
// log the servlet found
if (log.isDebugEnabled()) {