Example usage for org.springframework.web.servlet HandlerInterceptor afterCompletion

List of usage examples for org.springframework.web.servlet HandlerInterceptor afterCompletion

Introduction

In this page you can find the example usage for org.springframework.web.servlet HandlerInterceptor afterCompletion.

Prototype

default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        @Nullable Exception ex) throws Exception 

Source Link

Document

Callback after completion of request processing, that is, after rendering the view.

Usage

From source file:org.grails.plugins.web.filters.CompositeInterceptor.java

public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object o, Exception e)
        throws Exception {
    if (log.isDebugEnabled())
        log.debug("afterCompletion " + request + ", " + response + ", " + o + ", " + e);

    for (HandlerInterceptor handler : handlersReversed) {
        handler.afterCompletion(request, response, o, e);
    }/*  w w  w  .j a  v a2 s.  co  m*/
}

From source file:jun.learn.scene.handlerMapping.HandlerExecutionChain.java

/**
 * Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 * Will just invoke afterCompletion for all interceptors whose preHandle invocation
 * has successfully completed and returned true.
 *//*  w w w.j  a  v  a 2  s. c  om*/
void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, Exception ex)
        throws Exception {

    HandlerInterceptor[] interceptors = getInterceptors();
    if (!ObjectUtils.isEmpty(interceptors)) {
        for (int i = this.interceptorIndex; i >= 0; i--) {
            HandlerInterceptor interceptor = interceptors[i];
            try {
                interceptor.afterCompletion(request, response, this.handler, ex);
            } catch (Throwable ex2) {
                logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
            }
        }
    }
}

From source file:org.parancoe.web.plugin.PluginHelper.java

public void invokeAfterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception exception) {//from w w  w .ja  va2  s . com
    for (WebPlugin plugin : getWebPlugins()) {
        for (HandlerInterceptor interceptor : plugin.getInterceptors()) {
            try {
                interceptor.afterCompletion(request, response, handler, exception);
            } catch (Exception e) {
                log.error("error in afterCompletion for plugin '" + plugin.getName() + "'", e);
            }
        }
    }
}

From source file:org.zkoss.zk.grails.web.ZULUrlMappingsFilter.java

private boolean renderViewForUrlMappingInfo(HttpServletRequest request, HttpServletResponse response,
        UrlMappingInfo info, String viewName) {
    if (viewResolver != null) {
        View v;/*from w w w. ja  v a  2s  .co m*/
        try {
            // execute pre handler interceptors
            for (HandlerInterceptor handlerInterceptor : handlerInterceptors) {
                if (!handlerInterceptor.preHandle(request, response, this))
                    return false;
            }

            // execute post handlers directly after, since there is no controller. The filter has a chance to modify the view at this point;
            final ModelAndView modelAndView = new ModelAndView(viewName);
            for (HandlerInterceptor handlerInterceptor : handlerInterceptors) {
                handlerInterceptor.postHandle(request, response, this, modelAndView);
            }

            v = WebUtils.resolveView(request, info, modelAndView.getViewName(), viewResolver);
            v.render(modelAndView.getModel(), request, response);

            // after completion
            for (HandlerInterceptor handlerInterceptor : handlerInterceptors) {
                handlerInterceptor.afterCompletion(request, response, this, null);
            }
        } catch (Throwable e) {
            // let the sitemesh filter re-run for the error
            reapplySitemesh(request);
            for (HandlerInterceptor handlerInterceptor : handlerInterceptors) {
                try {
                    handlerInterceptor.afterCompletion(request, response, this,
                            e instanceof Exception ? (Exception) e
                                    : new GroovyPagesException(e.getMessage(), e));
                } catch (Exception e1) {
                    UrlMappingException ume = new UrlMappingException(
                            "Error executing filter after view error: " + e1.getMessage() + ". Original error: "
                                    + e.getMessage(),
                            e1);
                    filterAndThrow(ume);
                }
            }
            UrlMappingException ume = new UrlMappingException(
                    "Error mapping onto view [" + viewName + "]: " + e.getMessage(), e);
            filterAndThrow(ume);
        }
    }
    return true;
}

From source file:org.springframework.web.servlet.HandlerExecutionChain.java

/**
 * Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 * Will just invoke afterCompletion for all interceptors whose preHandle invocation
 * has successfully completed and returned true.
 *///from   w w  w .ja v a2 s .c  om
void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, @Nullable Exception ex)
        throws Exception {

    HandlerInterceptor[] interceptors = getInterceptors();
    if (!ObjectUtils.isEmpty(interceptors)) {
        for (int i = this.interceptorIndex; i >= 0; i--) {
            HandlerInterceptor interceptor = interceptors[i];
            try {
                interceptor.afterCompletion(request, response, this.handler, ex);
            } catch (Throwable ex2) {
                logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
            }
        }
    }
}

From source file:org.springframework.web.servlet.MyDispatcherServlet.java

/**
 * Trigger afterCompletion callbacks on the mapped HandlerInterceptors.
 * Will just invoke afterCompletion for all interceptors whose preHandle invocation
 * has successfully completed and returned true.
 * @param mappedHandler the mapped HandlerExecutionChain
 * @param interceptorIndex index of last interceptor that successfully completed
 * @param ex Exception thrown on handler execution, or <code>null</code> if none
 * @see HandlerInterceptor#afterCompletion
 *///  www.  j  a v  a 2s.  c o m
private void triggerAfterCompletion(HandlerExecutionChain mappedHandler, int interceptorIndex,
        HttpServletRequest request, HttpServletResponse response, Exception ex) throws Exception {

    // Apply afterCompletion methods of registered interceptors.
    if (mappedHandler != null) {
        HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
        if (interceptors != null) {
            for (int i = interceptorIndex; i >= 0; i--) {
                HandlerInterceptor interceptor = interceptors[i];
                try {
                    interceptor.afterCompletion(request, response, mappedHandler.getHandler(), ex);
                } catch (Throwable ex2) {
                    logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
                }
            }
        }
    }
}