RESTEasy | InterceptorContext和Interceptor是相互递归的
在AbstractWriterInterceptorContext里,我们可以在proceed()方法里看到对interceptors的aroundWriteTo(...)方法的调用:

注意上面的方法中,传入的参数是this,也就是AbstractWriterInterceptorContext自身。
然后Interceptor的约定是,在aroundWriteTo(...)方法的最后,要呼叫InterceptorContext的proceed()方法。
下面是GZIPEncodingInterceptor中aroundWriteTo(...)方法的例子:

这样等于interceptor context和interceptor的这两个方法之间就形成了一个recursive call chain。
那怎样算是这个递归到达一个结束点呢?
这个是靠在interceptor context当中的index计数来控制的:

可以看到,当index达到interceptors的数量的时候,就算是recursive call到顶了。
很多网络框架都用这种方式形成一种call chain,可以学习这种模式。
以下是上面整个逻辑过程的入口点:ServerResponseWriter的writeNomapResponse(...)方法当中:

以上是完整的分析过程。