Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1716

Logging request with ContainerRequestFilter/ContainerResponseFilter

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Unresolved
    • Major
    • None
    • 3.0.6.Final
    • None
    • 46088258

    Description

      I want to log entire request and response body. For logging purposes jax-rs have filters.

          public class ResponseLoggingFilter implements ContainerRequestFilter, ContainerResponseFilter {
              public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { 
              	System.out.println(IOUtils.toString(requestContext.getEntityStream(), "UTF-8")); // It's always empty string
              	System.out.println(responseContext.getEntity().toString());  // Here is actual response. It's OK
              }
              public void filter(ContainerRequestContext requestContext) throws IOException { 
              	System.out.println(IOUtils.toString(requestContext.getEntityStream(), "UTF-8")); // Here is actual response. But this request is empty in main code. 
              }
          }
      

      In response filter I cant get request body.
      In request filter I cat get it but:

      • I cant get a link between request body and response body.
      • Once wrote request body from stream setting this stream empty and I cant get it in my main code.
        I cant find a way to get request body that will not affect to main code.

      Attachments

        Activity

          People

            Unassigned Unassigned
            g0ddest Vitaliy Velikodniy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: