Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging JSON request and response for jersey

I have a JAVA web application application, which exposes RESTful apis. My requirement is to log all the JSON requests and responses that are handled by the server. Is there any parameter like -Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true for JAX-WS?

I am also exploring AOP approach. What method signature should I add in the AOP pattern?

I am using Tomcat server and jersey for the JAX-RS implementation.

like image 768
Manju Prabhu Avatar asked May 28 '12 07:05

Manju Prabhu


Video Answer


2 Answers

use LoggingFilter. Just add the following to your 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>
like image 86
Alex Stybaev Avatar answered Oct 12 '22 09:10

Alex Stybaev


<!-- 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)

like image 27
Upperstage Avatar answered Oct 12 '22 09:10

Upperstage