简体   繁体   English

记录泽西的JSON请求和响应

[英]Logging JSON request and response for jersey

I have a JAVA web application application, which exposes RESTful apis. 我有一个JAVA Web应用程序,它暴露了RESTful apis。 My requirement is to log all the JSON requests and responses that are handled by the server. 我的要求是记录服务器处理的所有JSON请求和响应。 Is there any parameter like -Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true for JAX-WS? 对于JAX-WS,是否有像-Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true参数?

I am also exploring AOP approach. 我也在探索AOP方法。 What method signature should I add in the AOP pattern? 我应该在AOP模式中添加什么方法签名?

I am using Tomcat server and jersey for the JAX-RS implementation. 我正在使用Tomcat服务器和jersey进行JAX-RS实现。

use LoggingFilter . 使用LoggingFilter Just add the following to your web.xml: 只需将以下内容添加到您的web.xml:

<init-param>
  <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
  <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
<init-param>
  <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
  <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
<!-- Enable Jersey tracing support in Glassfish -->
<init-param>
    <param-name>jersey.config.server.provider.classnames</param-name>
    <param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>

This worked for me (Jersey 2.x) 这对我有用(泽西岛2.x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM