Jersey:打印实际请求

2022-01-21 00:00:00 java 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).

推荐答案

如果你只是使用 Jersey Client API,LoggingFilter (客户端过滤器)应该可以帮助你:

If you're just using Jersey Client API, LoggingFilter (client filter) should help you:

Client client = Client.create();
client.addFilter(new LoggingFilter(System.out));
WebResource webResource = client.resource("http://localhost:9998/");
ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON)
                                         .get(ClientResponse.class);

否则,您可以使用其他 LoggingFilter(容器过滤器).

Otherwise, you can again log both request and response on server using other LoggingFilter (container filter).

相关文章