如何设置 Jersey REST Web 服务的超时?
我想知道如何使用 Jersey 设置 REST Web 服务的超时,并能够在服务中捕获它。我已经阅读了一些实现此目的的方法,例如在超时后调用另一个服务来检查当前服务是否处于活动状态,或者验证应用程序凭据等。
我宁愿不遵循这些方法。事实上,我想知道是否可以为 HTTP 请求或服务本身设置一个侦听器,如果 已达到超时时间。
我认为在服务主体中创建一个线程来充当侦听器可能是一个解决方案,但我想知道是否有更接近 Jersey 的解决方案。
I would like to know how to set a timeout for a REST web service with Jersey, and being able to catch it within the service. I've read some approaches to achieve this, such as calling another service after the timeout to check if the current service is active, or verifying application credentials, etc.
I'd rather not to follow these approaches. In fact, I would like to know if is possible to set a listener to the HTTP request, or to the service itself, that would execute some procedure if
the timeout is reached.
I suppose that creating a thread within the service body to act as listener could be a solution, but I'd like to know if there is a solution closer to Jersey.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我非常确定 Jersey 像许多其他 api 一样具有内置的客户端超时功能。
不想给你大量的代码,所以你可以查看这些帖子
不确定我没记错,但我认为您可以通过 setReadTimeout 和 setConnectTimeout* 使用此 clint api 设置它
https://jersey.java.net/apidocs/1.1.1-ea/jersey/com/sun/jersey/api/client/Client.html
I'm pretty sure that Jersey like many other api's has client timeout functionality built in.
Don't want to give you loads of code so you can check out these posts
Not sure I remember correctly but I think you can set it using this clint api through setReadTimeout and setConnectTimeout*
https://jersey.java.net/apidocs/1.1.1-ea/jersey/com/sun/jersey/api/client/Client.html