jersey2.6 过滤器和拦截器模块运行流程:
- Client request invoked: The POST request with attached entity is built on the client and invoked.
- 客户端发送POST请求,请求中内嵌客户端的实体信息。
- ClientRequestFilters: client request filters are executed on the client and they manipulate the request headers.
- 客户端请求过滤器:客户端请求过滤器在客户端执行,并且他们操作请求的标头类型信息。
- Client
WriterInterceptor
: As the request contains an entity, writer interceptor registered on the client is executed before a MessageBodyWriter is executed. It wraps the entity output stream with the GZipOutputStream. - 客户端写拦截器:根据请求中包含实体信息,此前在客户端注册的写拦截器先与写消息体执行。它用GZIP输出流包装实体输出流。
- Client MessageBodyWriter: message body writer is executed on the client which serializes the entity into the new GZipOutput stream. This stream zips the data and sends it to the "wire".
- 客户端写消息体:写消息体在客户端被执行,它把实体序列化并形成新的Gzip输出流。这些流压缩数据并且把数据传送给服务端。
- Server: server receives a request. Data of entity is compressed which means that pure read from the entity input stream would return compressed data.
- 服务端:服务端接收请求。纯粹的从实体输入流读将返回被压缩的数据。
- Server pre-matching ContainerRequestFilters: ContainerRequestFilters are executed that can manipulate resource method matching process.
- 服务端预匹配请求过滤器:操作资源方法匹配过程。
- Server: matching: resource method matching is done.
- 服务端:资源方法匹配完成
- Server: post-matching ContainerRequestFilters: ContainerRequestFilters post matching filters are executed. This include execution of all global filters (without name binding) and filters name-bound to the matched method.
- 服务端:post匹配请求过滤器:全局过滤器和用名字绑定的过滤器中匹配的方法将执行。
- Server
ReaderInterceptor
: reader interceptors are executed on the server. The GZIPReaderInterceptor wraps the input stream (the stream from the "wire") into the GZipInputStream and set it to context. - 服务端读拦截器:读拦截器包装输入流(从传入服务端的)成Gzip(example of GZIPReaderInterceptor)并放入容器中。
- Server MessageBodyReader: server message body reader is executed and it deserializes the entity from new GZipInputStream (get from the context). This means the reader will read unzipped data and not the compressed data from the "wire".
- 服务端读消息体:服务端读消息体从容器中得到的输入流反序列化实体。这意味着它将解压数据并且将解压的数据传给下一个处理对象。
- Server resource method is executed: the deserialized entity object is passed to the matched resource method as a parameter. The method returns this entity as a response entity.
- 服务资源方法:反序列化实体对象以参数形式被传输到匹配的资源方法。并把这个实体作为响应实体返回。
- Server ContainerResponseFilters are executed: response filters are executed on the server and they manipulate the response headers. This include all global bound filters (without name binding) and all filters name-bound to the resource method.
- 服务响应过滤器执行:操作响应标头信息。资源方法中的全局响应过滤器以及按名字绑定的响应过滤器都会执行。
- Server
WriterInterceptor
: is executed on the server. It wraps the original output stream with a new GZIPOuptutStream. The original stream is the stream that "goes to the wire" (output stream for response from the underlying server container). - 服务端写拦截器:包装原始输出流为新的Gzip输出流。输出流来自上一步的服务端容器。
- Server MessageBodyWriter: message body writer is executed on the server which serializes the entity into the GZIPOutputStream. This stream compresses the data and writes it to the original stream which sends this compressed data back to the client.
- 服务端写消息体:写消息体序列化实体至Gzip输出流。它压缩数据并且把它写入院士刘发送这些压缩数据返回给客户端。
- Client receives the response: the response contains compressed entity data.
- 客户端接收响应:响应中包含被压缩的实体数据。
- Client ClientResponseFilters: client response filters are executed and they manipulate the response headers.
- 客户端响应过滤器:客户端响应过滤器操作响应头信息。
- Client response is returned: the javax.ws.rs.core.Response is returned from the request invocation.
- 客户端响应返回:从请求的等待中返回响应
- Client code calls response.readEntity(): read entity is executed on the client to extract the entity from the response.
- 客户端代码调用方法readEntity():在客户端执行从响应中获得实体
- Client
ReaderInterceptor
: the client reader interceptor is executed when readEntity(Class) is called. The interceptor wraps the entity input stream with GZIPInputStream. This will decompress the data from the original input stream. - 客户端读拦截器:当readEntity被调用的时候,读拦截器执行。它用Gzip输入流包装实体输入流。这将从原始输入流中解压数据。
- Client MessageBodyReaders: client message body reader is invoked which reads decompressed data from GZIPInputStream and deserializes the entity.
- 客户端读消息体:当从Gzip输入流读解压数据并且反序列化实体的时候客户端读消息体被调用。
- Client: The entity is returned from the readEntity().客户端实体信息从readEntity()中返回。