Search in sources :

Example 1 with AbstractResourceCollector

use of org.apache.sling.servlets.resolver.internal.helper.AbstractResourceCollector in project sling by apache.

the class SlingServletResolver method resolveServletInternal.

/**
     * Resolve an appropriate servlet for a given request and resource type
     * using the provided ResourceResolver
     */
private Servlet resolveServletInternal(final SlingHttpServletRequest request, final Resource resource, final String scriptName, final ResourceResolver resolver) {
    Servlet servlet = null;
    // path of a servlet (or script)
    if (scriptName.charAt(0) == '/') {
        final String scriptPath = ResourceUtil.normalize(scriptName);
        if (this.isPathAllowed(scriptPath)) {
            final Resource res = resolver.getResource(scriptPath);
            servlet = this.getServlet(res);
            if (servlet != null && LOGGER.isDebugEnabled()) {
                LOGGER.debug("Servlet {} found using absolute resource type {}", RequestUtil.getServletName(servlet), scriptName);
            }
        } else {
            if (request != null) {
                request.getRequestProgressTracker().log("Will not look for a servlet at {0} as it is not in the list of allowed paths", scriptName);
            }
        }
    }
    if (servlet == null) {
        // the resource type is not absolute, so lets go for the deep search
        final AbstractResourceCollector locationUtil;
        if (request != null) {
            locationUtil = ResourceCollector.create(request, this.executionPaths, this.defaultExtensions);
        } else {
            locationUtil = NamedScriptResourceCollector.create(scriptName, resource, this.executionPaths);
        }
        servlet = getServletInternal(locationUtil, request, resolver);
        if (servlet != null && LOGGER.isDebugEnabled()) {
            LOGGER.debug("getServletInternal returns servlet {}", RequestUtil.getServletName(servlet));
        }
    }
    return servlet;
}
Also used : AbstractResourceCollector(org.apache.sling.servlets.resolver.internal.helper.AbstractResourceCollector) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) DefaultErrorHandlerServlet(org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet) HttpServlet(javax.servlet.http.HttpServlet) DefaultServlet(org.apache.sling.servlets.resolver.internal.defaults.DefaultServlet) Servlet(javax.servlet.Servlet) OptingServlet(org.apache.sling.api.servlets.OptingServlet)

Aggregations

Servlet (javax.servlet.Servlet)1 HttpServlet (javax.servlet.http.HttpServlet)1 Resource (org.apache.sling.api.resource.Resource)1 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)1 OptingServlet (org.apache.sling.api.servlets.OptingServlet)1 DefaultErrorHandlerServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet)1 DefaultServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultServlet)1 AbstractResourceCollector (org.apache.sling.servlets.resolver.internal.helper.AbstractResourceCollector)1