I am creating my own logging filter implementing ContainerRequestFilter and ContainerResponseFilter. I want to print the request entity only if the response failed eg. Response status code as 404, 500.
But I get empty string when I do request.getEntity() or request.getEntityInputStream()
in the filter method of ContainerResponseFilter();
It looks like jersey removes the content after reading it at resource level.
It needs to read the entity from the input stream, which is not resettable (the infrastructure involved doesn’t keep a copy of it). So, as the input stream is read previously, it is supposed to be have nothing when you call
request.getEntityInputStream()in the class that implementsContainerResponseFilter. LoggingFilter does the work for you. But as you mentioned, if you want to customize it, then you need write an implementation similar to that one, with added code to customize logging of course.