客户端请求过滤器与容器请求过滤器 [英] Clientrequestfilter vs Containerrequestfilter

查看:332
本文介绍了客户端请求过滤器与容器请求过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道过滤器用于处理请求,并且可以使用http标头和httpmethod进行操作,但是与之混淆

I knew filters are used to handle the request and can do things with http header and httpmethods, but am confused with

clientrequestfilter和containerrequestfilter有什么区别? 在哪种情况下,我们必须使用clientrequestfilter和containerrequestfilter?

What is the difference between clientrequestfilter and containerrequestfilter? Inwhich scenario we have to use clientrequestfilter and containerrequestfilter?

我尝试使用此网站,但没有尝试过详细信息.

I tried with this website but not any details about this.

请帮助我理解这一点.

推荐答案

REST交互有两个方面,即客户端和服务器. Jersey/JAX-RS-2同时具有客户端API和主"服务器端API.使用客户端API时,可以使用ClientRequestFilter,而使用服务器端API时,可以使用ContainerRequestFilter.不可能将它们混合和匹配,应严格将它们与交互的适当方面一起使用.

There are two side to a REST interaction, the client and the server. Jersey/JAX-RS-2 has both a Client API and the "main" Server side API. When working with the Client API, we could use the ClientRequestFilter, and when using the Server Side API, we would use the ContainerRequestFilter. There's no possibility to mix and match these, they should strictly be used with the appropriate side of the interaction.

一个ContainerRequestFilter(服务器端)示例将进行一些授权/身份验证,这是服务器端过滤器的一种非常常见的用例.在访问您的任何资源之前,将调用该过滤器

A ContainerRequestFilter (Server Side) example would be to do some authorization/authentication, which a pretty common use case for server side filter. The filter will be invoked before reaching any of your resources

Client --->  Internet ---> Server ---> Filter ---> Resource

ClientRequestFilter(客户端)示例将实现一些客户端缓存(模拟浏览器缓存).或者一个案例(已经实现)是一个过滤器,用于对用于BASIC身份验证的用户名和密码进行编码.在将请求实际发送到服务器之前,将调用客户端过滤器.

A ClientRequestFilter (Client Side) example would be implement some client side cache (sort of mocking a browser cache). Or a a case (which already has been implemented) is a filter to encode a user name and password for BASIC authentication. Before the request actually gets sent to the server, the client filter will get invoked.

Client ---> Filter ---> Internet ---> Server ---> Resource


还有XxxResponseFilters遵循以下流程


There are also XxxResponseFilters that follow the following flow

Resource ---> ContainerResponseFilter ---> Server ---> Internet ---> Client

Server ---> Internet ---> ClientResponseFilter ---> Client

这篇关于客户端请求过滤器与容器请求过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆