是否有一种优雅的方法来退出客户端雷克斯特福特?
我实现了一个 ClientRequestFilter。但是客户端的一次调用不应被过滤,这意味着如果请求来自此类(在我的例子中,该类称为 TokenClient),则该方法应该只返回。现在,如您所见,我检查路径,如果它包含 /token,它将返回。但我宁愿检查该类是否是 ofInstance TokenClient。我怎样才能做到这一点?
@Provider
public class MyClientRequestFilter implements ClientRequestFilter {
@Inject
MyClient myClient;
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
if(clientRequestContext.getUri().getPath().contains("/token"))
{
return;
}
String token= myClient.getToken();
clientRequestContext.getHeaders().addFirst("Authorization", "Bearer "+token);
}
}
I implemented a ClientRequestFilter. But one call of a client should not be filtered, which means if the request comes from this class (in my case the class is called TokenClient) the method should just return. Right now as you can see I check the path and if it contains /token it will return. But I would rather check if the class is ofInstance TokenClient. How can I do that ?
@Provider
public class MyClientRequestFilter implements ClientRequestFilter {
@Inject
MyClient myClient;
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
if(clientRequestContext.getUri().getPath().contains("/token"))
{
return;
}
String token= myClient.getToken();
clientRequestContext.getHeaders().addFirst("Authorization", "Bearer "+token);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一种方法可以知道它所描述的方法 此处。
本质上你做了类似的事情:
There is a way to know which method and it described here.
Essentially you do something like: