work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Zuul核心-预定义Filter

Posted on 2020-03-22 20:24  work hard work smart  阅读(167)  评论(0编辑  收藏  举报

1、核心Prefilter

 

ServletDetectionFilter源码如下,还是比较简单的

public class ServletDetectionFilter extends ZuulFilter {
    public ServletDetectionFilter() {
    }

    public String filterType() {
        return "pre";
    }

    public int filterOrder() {
        return -3;
    }

    public boolean shouldFilter() {
        return true;
    }

    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        if (!(request instanceof HttpServletRequestWrapper) && this.isDispatcherServletRequest(request)) {
            ctx.set("isDispatcherServletRequest", true);
        } else {
            ctx.set("isDispatcherServletRequest", false);
        }

        return null;
    }

    private boolean isDispatcherServletRequest(HttpServletRequest request) {
        return request.getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null;
    }
}

  

2、核心RoutingFilter

 

3、 核心PostFilter