public void doProcessRequest()

in src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java [216:338]


    public void doProcessRequest(
            final HttpServletRequest servletRequest,
            final HttpServletResponse servletResponse,
            final ResourceResolver resourceResolver)
            throws IOException {
        final ServletResolver sr = this.servletResolver;

        // check that we have all required services
        if (resourceResolver == null || sr == null) {
            // Dependencies are missing
            // In this case we must not use the Sling error handling infrastructure but
            // just return a 503 status response handled by the servlet container environment

            final int status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
            String errorMessage = "Required service missing (";
            if (resourceResolver == null) {
                errorMessage = errorMessage.concat("ResourceResolver");
                if (sr == null) {
                    errorMessage = errorMessage.concat(", ");
                }
            }
            if (sr == null) {
                errorMessage = errorMessage.concat("ServletResolver");
            }
            log.debug("{}, cannot service requests, sending status {}", errorMessage, status);
            servletResponse.sendError(status, errorMessage);
            return;
        }

        // setting the Sling request and response
        final RequestData requestData = new RequestData(
                this,
                servletRequest,
                servletResponse,
                protectHeadersOnInclude,
                checkContentTypeOnInclude,
                this.disableCheckCompliantGetUserPrincipal);
        final SlingJakartaHttpServletRequest request = requestData.getSlingRequest();
        final SlingJakartaHttpServletResponse response = requestData.getSlingResponse();

        try {
            if (getContentTypeHeaderState() != ContentTypeHeaderState.UNSET) {
                log.error(
                        "Content Type Header state has not been cleared properly, is set to {}",
                        getContentTypeHeaderState());
            }
            setContentTypeHeaderState(ContentTypeHeaderState.NOT_VIOLATED);

            // initialize the request data - resolve resource and servlet
            final Resource resource = requestData.initResource(resourceResolver);
            requestData.initServlet(resource, sr);

            final FilterHandle[] filters = filterManager.getFilters(FilterChainType.REQUEST);
            final FilterChain processor = new RequestSlingFilterChain(this, filters);

            request.getRequestProgressTracker()
                    .log("Applying ".concat(FilterChainType.REQUEST.name()).concat("filters"));

            processor.doFilter(request, response);

        } catch (final SlingJakartaHttpServletResponseImpl.WriterAlreadyClosedException wace) {
            // this is an exception case, log as error
            log.error("Writer has already been closed.", wace);

        } catch (final ResourceNotFoundException rnfe) {
            // send this exception as a 404 status
            log.debug("service: Resource {} not found", rnfe.getResource());
            handleError(HttpServletResponse.SC_NOT_FOUND, rnfe.getMessage(), request, response);

        } catch (final SlingException se) {
            // send this exception as is (albeit unwrapping and wrapped
            // exception.
            Throwable t = se;
            while (t instanceof SlingException && t.getCause() != null) {
                t = t.getCause();
            }
            handleError(requestData, "SlingException", t, request, response);

        } catch (final AccessControlException ace) {
            // SLING-319 if anything goes wrong, send 403/FORBIDDEN
            log.debug(
                    "service: Authenticated user {} does not have enough rights to executed requested action",
                    request.getRemoteUser());
            handleError(HttpServletResponse.SC_FORBIDDEN, null, request, response);

        } catch (final FileNotFoundException fnfe) {
            // send this exception as a 404 status
            log.debug("service: File not found: {}", fnfe.getMessage());
            handleError(HttpServletResponse.SC_NOT_FOUND, fnfe.getMessage(), request, response);

        } catch (final IOException ioe) {
            /**
             * handle all IOExceptions the same way; remember that there could be 2 major
             * types of IOExceptions
             * * exceptions thrown by the rendering process because it
             * does I/O
             * * exceptions thrown by the servlet engine when the connectivity to
             * the requester is problematic
             *
             * the second case does not need a proper error handling as the requester won't
             * see the result of it anyway, and for that case also the logging is not
             * helpful and should be limited to a minimum (if at all).
             *
             * But to ease the code and to provide a proper error handling for the
             * first case, both types are treated equally here.
             */
            handleError(requestData, "IOException", ioe, request, response);

        } catch (final Throwable t) {
            handleError(requestData, "Throwable", t, request, response);

        } finally {
            // record the request for the web console and info provider
            RequestInfoProviderImpl.recordRequest(request);

            final RequestProcessorMBeanImpl localBean = this.mbean;
            if (localBean != null) {
                localBean.addRequestData(requestData);
            }

            setContentTypeHeaderState(ContentTypeHeaderState.UNSET);
        }
    }