private void dispatch()

in src/main/java/org/apache/sling/engine/impl/request/SlingRequestDispatcher.java [156:202]


    private void dispatch(
            final ServletRequest request, final ServletResponse response, final DispatchingInfo dispatchingInfo)
            throws ServletException, IOException {
        SlingJakartaHttpServletRequest cRequest = RequestData.unwrap(request);
        RequestData rd = RequestData.getRequestData(cRequest);
        String absPath = getAbsolutePath(cRequest, path);
        RequestProgressTracker requestProgressTracker = cRequest.getRequestProgressTracker();

        // if the response is not an HttpServletResponse, fail gracefully not
        // doing anything
        if (!(response instanceof HttpServletResponse)) {
            log.error("include: Failed to include {}, response has wrong type", absPath);
            return;
        }

        if (resource == null) {
            String timerName = "resolveIncludedResource(" + absPath + ")";
            requestProgressTracker.startTimer(timerName);

            // resolve the absolute path in the resource resolver, using
            // only those parts of the path as if it would be request path
            resource = cRequest.getResourceResolver().resolve(absPath);

            // if the resource could not be resolved, fail gracefully
            if (resource == null) {
                log.error("include: Could not resolve {} to a resource, not including", absPath);
                return;
            }

            requestProgressTracker.logTimer(timerName, "path={0} resolves to Resource={1}", absPath, resource);
        }

        // ensure request path info and optional merges
        SlingRequestPathInfo info = getMergedRequestPathInfo(cRequest);
        requestProgressTracker.log("Including resource {0} ({1})", resource, info);
        if (dispatchingInfo.getType() == DispatcherType.INCLUDE) {
            final boolean protectHeaders = this.options != null
                    ? Boolean.parseBoolean(this.options.getOrDefault(
                            RequestDispatcherOptions.OPT_PROTECT_HEADERS_ON_INCLUDE,
                            String.valueOf(this.protectHeadersOnInclude)))
                    : this.protectHeadersOnInclude;
            dispatchingInfo.setProtectHeadersOnInclude(protectHeaders);
            dispatchingInfo.setCheckContentTypeOnInclude(this.checkContentTypeOnInclude);
        }

        rd.getSlingRequestProcessor().dispatchRequest(request, response, resource, info, dispatchingInfo);
    }