Jersey:打印实际请求
如何查看 Jersey 生成并发送到服务器的实际请求?我遇到了特定请求的问题,运行网络服务器的人要求查看完整的请求(带有标头等)。
How can I view the actual request that Jersey generates and sends to the server? I am having issues with a particular request and the fellow running the webserver asked to see the full request (with headers and the such).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您只是使用 Jersey Client API,LoggingFilter (客户端过滤器)应该可以帮助您:
否则,您可以使用其他 LoggingFilter (容器筛选)。
If you're just using Jersey Client API, LoggingFilter (client filter) should help you:
Otherwise, you can again log both request and response on server using other LoggingFilter (container filter).
从Jersey 2.23开始,有一个
LoggingFeature
您可以使用。以下是一个稍微简化的示例,请注意,您可以在WebTarget
也是如此。LoggingFeature
的 JavaDoc 表示请求“和/或”响应被记录下来,哈哈。在我的机器上,两者都被记录。Since Jersey 2.23, there's a
LoggingFeature
you could use. The following is a bit simplified example, please note that you can register the feature onWebTarget
as well.JavaDoc of
LoggingFeature
says that the request "and/or" the response is logged lol. On my machine, both are logged.@ivan.cikic 的答案适用于 Jersey 1.x。这是在 Jersey 2.x 中执行此操作的方法:
这无关紧要,但我只是不得不抱怨一下:新的
LoggingFilter
确实很烦人,因为它强制您使用 Java Util Logging 。如果它能让我控制记录器那就更好了。看起来像是设计上的倒退。@ivan.cikic's answer is for Jersey 1.x. Here's how you do it in Jersey 2.x:
This is irrelevant but I just have to complain: The new
LoggingFilter
is really annoying because it forces you to use Java Util Logging. It would be better if it gave me control over the logger. Seems like a step backwards in design.所有这些答案都非常接近,但它们缺乏记录请求和响应正文的设置。至少在 Jersey 2.30.1 中,这就是我完成记录请求和响应(包括它们各自的正文)的方式:
从技术上讲,
Level.All
和8192
值可能为null
。我只是在这里提供它们以简洁起见。All these answers are pretty close but they lack the setting to log the request and response body. At least with Jersey 2.30.1 this is how I accomplish logging the request and response including their respective bodies:
Technically the
Level.All
and8192
values could benull
. I just provide them here to be concise.对于 3.1.X 版本,它必须是:
Level.ALL
is NOTworkingFor version 3.1.X it must be:
Level.ALL
is NOT Working