public void service()

in src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java [100:165]


    public void service(ServletRequest req, ServletResponse res) throws ServletException {
        if (req instanceof HttpServletRequest && res instanceof HttpServletResponse) {

            HttpServletRequest request = (HttpServletRequest) req;

            // set the thread name according to the request
            String threadName = setThreadName(request);

            final RequestListenerManager localRLM = requestListenerManager;
            if (localRLM != null) {
                localRLM.sendEvent(request, SlingJakartaRequestEvent.EventType.EVENT_INIT);
            }

            ResourceResolver resolver = null;
            try {
                if (!allowTrace && "TRACE".equals(request.getMethod())) {
                    HttpServletResponse response = (HttpServletResponse) res;
                    response.setStatus(405);
                    response.setHeader("Allow", "GET, HEAD, POST, PUT, DELETE, OPTIONS");
                    return;
                }

                // get ResourceResolver (set by AuthenticationSupport)
                Object resolverObject = request.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
                resolver = (resolverObject instanceof ResourceResolver) ? (ResourceResolver) resolverObject : null;

                // real request handling for HTTP requests
                // we don't check for null of requestProcessorImpl as we would throw an exception anyway in that case
                requestProcessorImpl.doProcessRequest(request, (HttpServletResponse) res, resolver);

            } catch (ClientAbortException cae) {
                log.debug(
                        "service: ClientAbortException, probable cause is client aborted request or network problem",
                        cae);

            } catch (Throwable t) {

                // some failure while handling the request, log the issue
                // and terminate. We do not call error handling here, because
                // we assume the real request handling would have done this.
                // So here we just log

                log.error("service: Uncaught Problem handling the request", t);

            } finally {

                // close the resource resolver (not relying on servlet request
                // listener to do this for now; see SLING-1270)
                if (resolver != null) {
                    resolver.close();
                }

                if (localRLM != null) {
                    localRLM.sendEvent(request, SlingJakartaRequestEvent.EventType.EVENT_DESTROY);
                }

                // reset the thread name
                if (threadName != null) {
                    Thread.currentThread().setName(threadName);
                }
            }

        } else {
            throw new ServletException("Apache Sling must be run in an HTTP servlet environment.");
        }
    }