Search in sources :

Example 1 with StartupInfoProvider

use of org.apache.sling.startupfilter.StartupInfoProvider in project sling by apache.

the class StartupFilterImpl method doFilter.

/** @inheritDoc */
@Override
public void doFilter(ServletRequest request, ServletResponse sr, FilterChain chain) throws IOException, ServletException {
    // Disable if a StartupFilterDisabler is present
    if (startupFilterDisabler != null) {
        log.info("StartupFilterDisabler service present, disabling StartupFilter ({})", startupFilterDisabler.getReason());
        disable();
        chain.doFilter(request, sr);
        return;
    }
    // Bypass for the managerRoot path
    if (request instanceof HttpServletRequest) {
        final HttpServletRequest req = (HttpServletRequest) request;
        final String path = req.getServletPath() + (req.getPathInfo() == null ? "" : req.getPathInfo());
        if (managerRoot != null && managerRoot.length() > 0 && path.startsWith(managerRoot)) {
            log.debug("Bypassing filter for path {} which starts with {}", path, managerRoot);
            chain.doFilter(request, sr);
            return;
        }
    }
    updateProviders();
    final StringBuilder sb = new StringBuilder();
    sb.append(defaultMessage);
    for (StartupInfoProvider p : providers) {
        sb.append('\n');
        sb.append(p.getProgressInfo());
    }
    // Do not use setError to avoid triggering the container's error page,
    // as that might cascade other errors during startup
    final HttpServletResponse response = (HttpServletResponse) sr;
    response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(sb.toString());
    response.getWriter().flush();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) StartupInfoProvider(org.apache.sling.startupfilter.StartupInfoProvider)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 StartupInfoProvider (org.apache.sling.startupfilter.StartupInfoProvider)1