Solon

五、请求处理过程示意图(AOP)

</> markdown

关键接口预览

1、Filter, 过滤器(环绕式)

@FunctionalInterface
public interface Filter {
    /**
     * 过滤
     * */
    void doFilter(Context ctx, FilterChain chain) throws Throwable;
}

2、RouterInterceptor, 路由拦截器(环绕式)

public interface RouterInterceptor {
    /**
     * 路径匹配模式(控制拦截的路径区配)
     * */
    default PathRule pathPatterns(){
        //null 表示全部
        return null;
    }
    
    /**
     * 拦截
     */
    void doIntercept(Context ctx,
                     @Nullable Handler mainHandler,
                     RouterInterceptorChain chain) throws Throwable;

    /**
     * 提交结果(action / render 执行前调用)
     */
    default Object postResult(Context ctx, @Nullable Object result) throws Throwable {
        return result;
    }
}

3、@Before、@After,处理器(责任链式)

@FunctionalInterface
public interface Handler {
    /**
    * 处理
    */
    void handle(Context ctx) throws Throwable;
}

//绑定 Handler 接口实现
@Before(Handler.class)

4、Interceptor, 拦截器(环绕式)

@FunctionalInterface
public interface Interceptor {
    /**
     * 拦截
     * */
    Object doIntercept(Invocation inv) throws Throwable;
}

//绑定 Interceptor 接口实现
@Around(Interceptor.class)