Search in sources :

Example 1 with RequestProgressTracker

use of org.apache.sling.api.request.RequestProgressTracker in project sling by apache.

the class RequestProgressTrackerLogFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    chain.doFilter(request, response);
    if (request instanceof SlingHttpServletRequest) {
        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
        final RequestProgressTracker rpt = slingRequest.getRequestProgressTracker();
        rpt.done();
        if (log.isDebugEnabled() && allowDuration(rpt) && allowExtension(extractExtension(slingRequest))) {
            if (configuration.compactLogFormat()) {
                logCompactFormat(rpt);
            } else {
                logDefaultFormat(rpt);
            }
        }
    }
}
Also used : RequestProgressTracker(org.apache.sling.api.request.RequestProgressTracker) SlingRequestProgressTracker(org.apache.sling.engine.impl.request.SlingRequestProgressTracker) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 2 with RequestProgressTracker

use of org.apache.sling.api.request.RequestProgressTracker in project sling by apache.

the class AbstractSlingFilterChain method trackFilter.

// ---------- internal helper
private void trackFilter(ServletRequest request, FilterHandle filter) {
    RequestData data = RequestData.getRequestData(request);
    if (data != null) {
        RequestProgressTracker tracker = data.getRequestProgressTracker();
        tracker.log("Calling filter: {0}", filter.getFilter().getClass().getName());
    }
    filter.track();
}
Also used : RequestData(org.apache.sling.engine.impl.request.RequestData) RequestProgressTracker(org.apache.sling.api.request.RequestProgressTracker)

Example 3 with RequestProgressTracker

use of org.apache.sling.api.request.RequestProgressTracker in project sling by apache.

the class AbstractSlingFilterChain method consolidateFilterTimings.

private void consolidateFilterTimings(ServletRequest request) {
    if (filters != null) {
        RequestData data = RequestData.getRequestData(request);
        RequestProgressTracker tracker = (data != null) ? data.getRequestProgressTracker() : null;
        for (int i = filters.length - 1; i > 0; i--) {
            filters[i].trackTime(times[i] - times[i + 1]);
            if (tracker != null) {
                tracker.log("Filter timing: filter={0}, inner={1}, total={2}, outer={3}", filters[i].getFilter().getClass().getName(), times[i + 1], times[i], (times[i] - times[i + 1]));
            }
        }
    }
}
Also used : RequestData(org.apache.sling.engine.impl.request.RequestData) RequestProgressTracker(org.apache.sling.api.request.RequestProgressTracker)

Example 4 with RequestProgressTracker

use of org.apache.sling.api.request.RequestProgressTracker in project sling by apache.

the class SlingRequestDispatcher method dispatch.

private void dispatch(ServletRequest request, ServletResponse sResponse, boolean include) throws ServletException, IOException {
    SlingHttpServletRequest cRequest = RequestData.unwrap(request);
    RequestData rd = RequestData.getRequestData(cRequest);
    String absPath = getAbsolutePath(cRequest, path);
    RequestProgressTracker requestProgressTracker = cRequest.getRequestProgressTracker();
    // doing anything
    if (!(sResponse 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);
    rd.getSlingRequestProcessor().dispatchRequest(request, sResponse, resource, info, include);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestProgressTracker(org.apache.sling.api.request.RequestProgressTracker) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 5 with RequestProgressTracker

use of org.apache.sling.api.request.RequestProgressTracker in project sling by apache.

the class SlingServletResolver method handleError.

// ---------- ErrorHandler interface --------------------------------------
/**
     * @see org.apache.sling.engine.servlets.ErrorHandler#handleError(int,
     *      String, SlingHttpServletRequest, SlingHttpServletResponse)
     */
@Override
public void handleError(final int status, final String message, final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException {
    // do not handle, if already handling ....
    if (request.getAttribute(SlingConstants.ERROR_REQUEST_URI) != null) {
        LOGGER.error("handleError: Recursive invocation. Not further handling status " + status + "(" + message + ")");
        return;
    }
    // start tracker
    RequestProgressTracker tracker = request.getRequestProgressTracker();
    String timerName = "handleError:status=" + status;
    tracker.startTimer(timerName);
    final ResourceResolver scriptResolver = this.getScriptResourceResolver();
    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), DEFAULT_ERROR_HANDLER_RESOURCE_TYPE, resource, this.executionPaths);
        Servlet servlet = getServletInternal(locationUtil, request, scriptResolver);
        // fall back to default servlet if none
        if (servlet == null) {
            servlet = getDefaultErrorServlet(request, resource, scriptResolver);
        }
        // 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");
    }
}
Also used : ResourceCollector(org.apache.sling.servlets.resolver.internal.helper.ResourceCollector) AbstractResourceCollector(org.apache.sling.servlets.resolver.internal.helper.AbstractResourceCollector) NamedScriptResourceCollector(org.apache.sling.servlets.resolver.internal.helper.NamedScriptResourceCollector) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) 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) RequestProgressTracker(org.apache.sling.api.request.RequestProgressTracker)

Aggregations

RequestProgressTracker (org.apache.sling.api.request.RequestProgressTracker)11 Servlet (javax.servlet.Servlet)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)4 Resource (org.apache.sling.api.resource.Resource)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4 HttpServlet (javax.servlet.http.HttpServlet)3 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)3 OptingServlet (org.apache.sling.api.servlets.OptingServlet)3 DefaultErrorHandlerServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet)3 DefaultServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultServlet)3 PrintWriter (java.io.PrintWriter)2 RequestData (org.apache.sling.engine.impl.request.RequestData)2 AbstractResourceCollector (org.apache.sling.servlets.resolver.internal.helper.AbstractResourceCollector)2 NamedScriptResourceCollector (org.apache.sling.servlets.resolver.internal.helper.NamedScriptResourceCollector)2 ResourceCollector (org.apache.sling.servlets.resolver.internal.helper.ResourceCollector)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 JspException (javax.servlet.jsp.JspException)1 BodyContent (javax.servlet.jsp.tagext.BodyContent)1 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1 SlingBindings (org.apache.sling.api.scripting.SlingBindings)1