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);
}
}
}
}
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();
}
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]));
}
}
}
}
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);
}
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");
}
}
Aggregations