Package org.apache.sling.api.request

Examples of org.apache.sling.api.request.RequestProgressTracker


            throws ServletException, IOException {
        this.current++;

        if (this.current < this.filters.length) {
           
            RequestProgressTracker tracker = ((SlingHttpServletRequest) request).getRequestProgressTracker();
            tracker.log("Calling filter: {0}", this.filters[this.current].getClass().getName());
           
            this.filters[this.current].doFilter(request, response, this);
        } else {
            this.render((SlingHttpServletRequest) request,
                (SlingHttpServletResponse) response);
View Full Code Here


                + status + "(" + message + ")");
            return;
        }

        // start tracker
        RequestProgressTracker tracker = request.getRequestProgressTracker();
        String timerName = "handleError:status=" + status;
        tracker.startTimer(timerName);

        try {

            // find the error handler component
            Resource resource = getErrorResource(request);

            // find a servlet for the status as the method name
            ResourceCollector locationUtil = new ResourceCollector(
                String.valueOf(status),
                ServletResolverConstants.ERROR_HANDLER_PATH);
            Servlet servlet = getServlet(locationUtil, request, resource);

            // fall back to default servlet if none
            if (servlet == null) {
                servlet = getDefaultErrorServlet();
            }

            // set the message properties
            request.setAttribute(ERROR_STATUS, new Integer(status));
            request.setAttribute(ERROR_MESSAGE, message);

            // the servlet name for a sendError handling is still stored
            // as the request attribute
            Object servletName = request.getAttribute(SLING_CURRENT_SERVLET_NAME);
            if (servletName instanceof String) {
                request.setAttribute(ERROR_SERVLET_NAME, servletName);
            }

            // log a track entry after resolution before calling the handler
            tracker.logTimer(timerName, "Using handler {0}",
                RequestUtil.getServletName(servlet));

            handleError(servlet, request, response);

        } finally {

            tracker.logTimer(timerName, "Error handler finished");

        }
    }
View Full Code Here

                throwable);
            return;
        }

        // start tracker
        RequestProgressTracker tracker = request.getRequestProgressTracker();
        String timerName = "handleError:throwable="
            + throwable.getClass().getName();
        tracker.startTimer(timerName);

        try {

            // find the error handler component
            Servlet servlet = null;
            Resource resource = getErrorResource(request);

            Class<?> tClass = throwable.getClass();
            while (servlet == null && tClass != Object.class) {
                // find a servlet for the simple class name as the method name
                ResourceCollector locationUtil = new ResourceCollector(
                    tClass.getSimpleName(),
                    ServletResolverConstants.ERROR_HANDLER_PATH);
                servlet = getServlet(locationUtil, request, resource);

                // go to the base class
                tClass = tClass.getSuperclass();
            }

            if (servlet == null) {
                servlet = getDefaultErrorServlet();
            }

            // set the message properties
            request.setAttribute(SlingConstants.ERROR_EXCEPTION, throwable);
            request.setAttribute(SlingConstants.ERROR_EXCEPTION_TYPE,
                throwable.getClass());
            request.setAttribute(SlingConstants.ERROR_MESSAGE,
                throwable.getMessage());

            // log a track entry after resolution before calling the handler
            tracker.logTimer(timerName, "Using handler {0}",
                RequestUtil.getServletName(servlet));

            handleError(servlet, request, response);

        } finally {

            tracker.logTimer(timerName, "Error handler finished");

        }
    }
View Full Code Here

    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;

        // first check whether the type of a resource is the absolute
        // path of a servlet (or script)
        String type = resource.getResourceType();
        if (type.charAt(0) == '/') {
            Resource res = request.getResourceResolver().getResource(type);
            if (res != null) {
                servlet = res.adaptTo(Servlet.class);
            }
        }

        // 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);
        }

        // last resort, use the core bundle default servlet
        if (servlet == null) {
            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()) {
View Full Code Here

                pw.println("<h3>Exception stacktrace:</h3>");
                pw.println("<pre>");
                throwable.printStackTrace(pw);
                pw.println("</pre>");

                RequestProgressTracker tracker = ((SlingHttpServletRequest) request).getRequestProgressTracker();
                pw.println("<h3>Request Progress:</h3>");
                pw.println("<pre>");
                tracker.dump(pw);
                pw.println("</pre>");
            }

            pw.println("<hr /><address>");
            pw.println(getServerInfo());
View Full Code Here

            FilterChain chain) throws IOException, ServletException {

        chain.doFilter(request, response);

        if (request instanceof SlingHttpServletRequest) {
            final RequestProgressTracker t = ((SlingHttpServletRequest) request).getRequestProgressTracker();
            t.done();

            if (log.isDebugEnabled()) {
                int requestId = 0;
                synchronized (getClass()) {
                    requestId = ++requestCounter;
                }
                final Iterator<String> it = t.getMessages();
                while (it.hasNext()) {
                    log.debug("REQUEST_{} - " + it.next(), requestId);
                }
            }
        }
View Full Code Here

    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()) {
View Full Code Here

                + status + "(" + message + ")");
            return;
        }

        // start tracker
        RequestProgressTracker tracker = request.getRequestProgressTracker();
        String timerName = "handleError:status=" + status;
        tracker.startTimer(timerName);

        try {

            // find the error handler component
            Resource resource = getErrorResource(request);

            // find a servlet for the status as the method name
            ResourceCollector locationUtil = new ResourceCollector(
                String.valueOf(status),
                ServletResolverConstants.ERROR_HANDLER_PATH);
            Servlet servlet = getServlet(locationUtil, request, resource);

            // fall back to default servlet if none
            if (servlet == null) {
                servlet = getDefaultErrorServlet();
            }

            // set the message properties
            request.setAttribute(ERROR_STATUS, new Integer(status));
            request.setAttribute(ERROR_MESSAGE, message);

            // the servlet name for a sendError handling is still stored
            // as the request attribute
            Object servletName = request.getAttribute(SLING_CURRENT_SERVLET_NAME);
            if (servletName instanceof String) {
                request.setAttribute(ERROR_SERVLET_NAME, servletName);
            }

            // log a track entry after resolution before calling the handler
            tracker.logTimer(timerName, "Using handler {0}",
                RequestUtil.getServletName(servlet));

            handleError(servlet, request, response);

        } finally {

            tracker.logTimer(timerName, "Error handler finished");

        }
    }
View Full Code Here

                throwable);
            return;
        }

        // start tracker
        RequestProgressTracker tracker = request.getRequestProgressTracker();
        String timerName = "handleError:throwable="
            + throwable.getClass().getName();
        tracker.startTimer(timerName);

        try {

            // find the error handler component
            Servlet servlet = null;
            Resource resource = getErrorResource(request);

            Class<?> tClass = throwable.getClass();
            while (servlet == null && tClass != Object.class) {
                // find a servlet for the simple class name as the method name
                ResourceCollector locationUtil = new ResourceCollector(
                    tClass.getSimpleName(),
                    ServletResolverConstants.ERROR_HANDLER_PATH);
                servlet = getServlet(locationUtil, request, resource);

                // go to the base class
                tClass = tClass.getSuperclass();
            }

            if (servlet == null) {
                servlet = getDefaultErrorServlet();
            }

            // set the message properties
            request.setAttribute(SlingConstants.ERROR_EXCEPTION, throwable);
            request.setAttribute(SlingConstants.ERROR_EXCEPTION_TYPE,
                throwable.getClass());
            request.setAttribute(SlingConstants.ERROR_MESSAGE,
                throwable.getMessage());

            // log a track entry after resolution before calling the handler
            tracker.logTimer(timerName, "Using handler {0}",
                RequestUtil.getServletName(servlet));

            handleError(servlet, request, response);

        } finally {

            tracker.logTimer(timerName, "Error handler finished");

        }
    }
View Full Code Here

            printStackTrace(escapingWriter, throwable);
            escapingWriter.flush();
            pw.println("</pre>");
           
            if (req instanceof SlingHttpServletRequest) {
                RequestProgressTracker tracker = ((SlingHttpServletRequest) req).getRequestProgressTracker();
                pw.println("<h3>Request Progress:</h3>");
                pw.println("<pre>");
                pw.flush();
                tracker.dump(escapingWriter);
                escapingWriter.flush();
                pw.println("</pre>");
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.request.RequestProgressTracker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.