Search in sources :

Example 1 with SlingServletException

use of org.apache.sling.api.SlingServletException in project sling by apache.

the class JspServletWrapper method service.

/**
     * @param bindings
     * @throws SlingIOException
     * @throws SlingServletException
     * @throws IllegalArgumentException if the Jasper Precompile controller
     *             request parameter has an illegal value.
     */
public void service(final SlingBindings bindings) {
    final SlingHttpServletRequest request = bindings.getRequest();
    final Object oldValue = request.getAttribute(SlingBindings.class.getName());
    try {
        request.setAttribute(SlingBindings.class.getName(), bindings);
        service(request, bindings.getResponse());
    } catch (SlingException se) {
        // rethrow as is
        throw se;
    } catch (IOException ioe) {
        throw new SlingIOException(ioe);
    } catch (ServletException se) {
        throw new SlingServletException(se);
    } finally {
        request.setAttribute(SlingBindings.class.getName(), oldValue);
    }
}
Also used : ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingBindings(org.apache.sling.api.scripting.SlingBindings) SlingException(org.apache.sling.api.SlingException) IOException(java.io.IOException) SlingIOException(org.apache.sling.api.SlingIOException) SlingIOException(org.apache.sling.api.SlingIOException) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Example 2 with SlingServletException

use of org.apache.sling.api.SlingServletException 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 3 with SlingServletException

use of org.apache.sling.api.SlingServletException 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)

Example 4 with SlingServletException

use of org.apache.sling.api.SlingServletException in project sling by apache.

the class JavaScriptEngineFactory method callServlet.

/**
     * Call the servlet.
     * @param bindings The bindings for the script invocation
     * @param scriptHelper The script helper.
     * @param context The script context.
     * @throws SlingServletException
     * @throws SlingIOException
     */
private void callServlet(final Bindings bindings, final SlingScriptHelper scriptHelper, final ScriptContext context) {
    // create a SlingBindings object
    final SlingBindings slingBindings = new SlingBindings();
    slingBindings.putAll(bindings);
    ResourceResolver resolver = (ResourceResolver) context.getAttribute(SlingScriptConstants.ATTR_SCRIPT_RESOURCE_RESOLVER, SlingScriptConstants.SLING_SCOPE);
    if (resolver == null) {
        resolver = scriptHelper.getScript().getScriptResource().getResourceResolver();
    }
    ioProvider.setRequestResourceResolver(resolver);
    final SlingHttpServletRequest request = slingBindings.getRequest();
    final Object oldValue = request.getAttribute(SlingBindings.class.getName());
    try {
        final ServletWrapper servlet = getWrapperAdapter(scriptHelper);
        request.setAttribute(SlingBindings.class.getName(), slingBindings);
        servlet.service(request, slingBindings.getResponse());
    } catch (SlingException se) {
        // rethrow as is
        throw se;
    } catch (IOException ioe) {
        throw new SlingIOException(ioe);
    } catch (ServletException se) {
        throw new SlingServletException(se);
    } catch (Exception ex) {
        throw new SlingException(null, ex);
    } finally {
        request.setAttribute(SlingBindings.class.getName(), oldValue);
        ioProvider.resetRequestResourceResolver();
    }
}
Also used : ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingBindings(org.apache.sling.api.scripting.SlingBindings) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) SlingException(org.apache.sling.api.SlingException) IOException(java.io.IOException) SlingIOException(org.apache.sling.api.SlingIOException) SlingIOException(org.apache.sling.api.SlingIOException) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) ServletException(javax.servlet.ServletException) ScriptException(javax.script.ScriptException) SlingServletException(org.apache.sling.api.SlingServletException) SlingException(org.apache.sling.api.SlingException) IOException(java.io.IOException) SlingIOException(org.apache.sling.api.SlingIOException)

Aggregations

ServletException (javax.servlet.ServletException)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)4 SlingServletException (org.apache.sling.api.SlingServletException)4 IOException (java.io.IOException)2 FilterChain (javax.servlet.FilterChain)2 SlingException (org.apache.sling.api.SlingException)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 SlingIOException (org.apache.sling.api.SlingIOException)2 SlingBindings (org.apache.sling.api.scripting.SlingBindings)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 ScriptException (javax.script.ScriptException)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1