Search in sources :

Example 1 with AbstractSlingFilterChain

use of org.apache.sling.engine.impl.filter.AbstractSlingFilterChain in project sling by apache.

the class SlingRequestProcessorImpl method handleError.

// ---------- Error Handling with Filters
void handleError(final int status, final String message, final SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
    // wrap the response ensuring getWriter will fall back to wrapping
    // the response output stream if reset does not reset this
    response = new ErrorResponseWrapper(response);
    FilterHandle[] filters = filterManager.getFilters(FilterChainType.ERROR);
    if (filters != null && filters.length > 0) {
        FilterChain processor = new AbstractSlingFilterChain(filters) {

            @Override
            protected void render(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
                errorHandler.handleError(status, message, request, response);
            }
        };
        request.getRequestProgressTracker().log("Applying " + FilterChainType.ERROR + " filters");
        try {
            processor.doFilter(request, response);
        } catch (ServletException se) {
            throw new SlingServletException(se);
        }
    } else {
        errorHandler.handleError(status, message, request, response);
    }
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) FilterHandle(org.apache.sling.engine.impl.filter.FilterHandle) SlingServletException(org.apache.sling.api.SlingServletException) RequestSlingFilterChain(org.apache.sling.engine.impl.filter.RequestSlingFilterChain) SlingComponentFilterChain(org.apache.sling.engine.impl.filter.SlingComponentFilterChain) FilterChain(javax.servlet.FilterChain) AbstractSlingFilterChain(org.apache.sling.engine.impl.filter.AbstractSlingFilterChain) AbstractSlingFilterChain(org.apache.sling.engine.impl.filter.AbstractSlingFilterChain) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 2 with AbstractSlingFilterChain

use of org.apache.sling.engine.impl.filter.AbstractSlingFilterChain in project sling by apache.

the class SlingRequestProcessorImpl method handleError.

// just rethrow the exception as explained in the class comment
private void handleError(final Throwable throwable, final SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
    // wrap the response ensuring getWriter will fall back to wrapping
    // the response output stream if reset does not reset this
    response = new ErrorResponseWrapper(response);
    FilterHandle[] filters = filterManager.getFilters(FilterChainType.ERROR);
    if (filters != null && filters.length > 0) {
        FilterChain processor = new AbstractSlingFilterChain(filters) {

            @Override
            protected void render(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
                errorHandler.handleError(throwable, request, response);
            }
        };
        request.getRequestProgressTracker().log("Applying " + FilterChainType.ERROR + " filters");
        try {
            processor.doFilter(request, response);
        } catch (ServletException se) {
            throw new SlingServletException(se);
        }
    } else {
        errorHandler.handleError(throwable, request, response);
    }
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) FilterHandle(org.apache.sling.engine.impl.filter.FilterHandle) SlingServletException(org.apache.sling.api.SlingServletException) RequestSlingFilterChain(org.apache.sling.engine.impl.filter.RequestSlingFilterChain) SlingComponentFilterChain(org.apache.sling.engine.impl.filter.SlingComponentFilterChain) FilterChain(javax.servlet.FilterChain) AbstractSlingFilterChain(org.apache.sling.engine.impl.filter.AbstractSlingFilterChain) AbstractSlingFilterChain(org.apache.sling.engine.impl.filter.AbstractSlingFilterChain) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Aggregations

FilterChain (javax.servlet.FilterChain)2 ServletException (javax.servlet.ServletException)2 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 SlingServletException (org.apache.sling.api.SlingServletException)2 AbstractSlingFilterChain (org.apache.sling.engine.impl.filter.AbstractSlingFilterChain)2 FilterHandle (org.apache.sling.engine.impl.filter.FilterHandle)2 RequestSlingFilterChain (org.apache.sling.engine.impl.filter.RequestSlingFilterChain)2 SlingComponentFilterChain (org.apache.sling.engine.impl.filter.SlingComponentFilterChain)2