package org.treeleaf.web.spring.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 提供聚合读个HandlerInterceptor的方法
 * <p>
 * Created by yaoshuhong on 2015/5/5.
 */
public class MultipleHandlerInerceptor implements HandlerInterceptor {

    private List<HandlerInterceptor> handlers = new ArrayList<>();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        for (HandlerInterceptor item : handlers) {
            if (!item.preHandle(request, response, handler)) {
                return false;
            }
        }

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        for (HandlerInterceptor item : handlers) {
            item.postHandle(request, response, handler, modelAndView);
        }
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        for (HandlerInterceptor item : handlers) {
            item.afterCompletion(request, response, handler, ex);
        }
    }

    public void setHandlers(List<HandlerInterceptor> handlers) {
        this.handlers = handlers;
    }
}

@@ -39,16 +39,73 @@
 eptor;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -386,16 +386,18 @@
 rceptor%E7%9A%84
+%E9%80%82%E9%85%8D
 %E6%96%B9%E6%B3%95%0A * %3Cp
@@ -580,16 +580,107 @@
 t%3C%3E();%0A%0A
+    private static Logger log = LoggerFactory.getLogger(MultipleHandlerInerceptor.class);%0A%0A
     @Ove
@@ -1171,32 +1171,88 @@
  %7B%0A        for (
+int i = handlers.size() - 1; i %3E= 0; i--) %7B%0A            
 HandlerIntercept
@@ -1251,33 +1251,33 @@
 nterceptor item 
-:
+=
  handlers) %7B%0A   
@@ -1261,36 +1261,63 @@
  item = handlers
-) %7B%0A
+.get(i);%0A            try %7B%0A    
             item
@@ -1371,16 +1371,100 @@
 dView);%0A
+            %7D catch (Exception e) %7B%0A                log.error(%22%22, e);%0A            %7D%0A
         
@@ -1630,32 +1630,88 @@
  %7B%0A        for (
+int i = handlers.size() - 1; i %3E= 0; i--) %7B%0A            
 HandlerIntercept
@@ -1710,33 +1710,33 @@
 nterceptor item 
-:
+=
  handlers) %7B%0A   
@@ -1720,36 +1720,63 @@
  item = handlers
-) %7B%0A
+.get(i);%0A            try %7B%0A    
             item
@@ -1825,16 +1825,100 @@
 r, ex);%0A
+            %7D catch (Exception e) %7B%0A                log.error(%22%22, e);%0A            %7D%0A
         

添加支持多个spring mvc拦截器的适配类