Class HttpRequestResponseLogUtil


  • public class HttpRequestResponseLogUtil
    extends Object
    Utility for logging requests / responses.

    The utility can be used to generate HTTP request / response log strings. Both for incoming service calls as outgoing calls (i.e. calls to backend systems).

    Since:
    2.0.0
    Author:
    Rutger Lubbers
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      String createLogString​(String requestLine, org.springframework.http.HttpHeaders headers, byte[] body, String characterEncoding)
      Create a log string for the given requestLine, headers and body.
      String createLogString​(String requestLine, org.springframework.http.HttpHeaders headers, byte[] body, Charset charset)
      Create a log string for the given requestLine, headers and body.
      String createLogString​(String requestLine, org.springframework.http.HttpHeaders headers, String body)
      Create a log string for the given requestLine, headers and body.
      String createLogString​(org.springframework.http.HttpHeaders headers, byte[] body)
      Create a log string for the given headers and body with the platform's default charset.
      String createLogString​(org.springframework.http.HttpHeaders headers, byte[] body, String characterEncoding)
      Create a log string for the given headers and body with the given characterEncoding.
      String createLogString​(org.springframework.http.HttpHeaders headers, byte[] body, Charset charset)
      Create a log string for the given headers and body with the given charset.
      String createLogString​(org.springframework.http.HttpHeaders headers, String body)
      Create a log string for the given headers and body with the platform's default charset.
      String createRequestLine​(String request, String protocol)
      Create a request line for the requestUri and protocol.
      String formatRequest​(String request, javax.servlet.http.HttpServletRequest servletRequest)
      Format the request as a nicely formatted string.
      org.springframework.http.HttpHeaders getHeaders​(javax.servlet.http.HttpServletRequest request)
      Create HttpHeaders for the request.
      org.springframework.http.HttpHeaders getHeaders​(javax.servlet.http.HttpServletResponse response)
      Create HttpHeaders for the response.
      String getRequestUri​(javax.servlet.http.HttpServletRequest servletRequest)
      Transform the request into a log line.
    • Constructor Detail

      • HttpRequestResponseLogUtil

        public HttpRequestResponseLogUtil()
    • Method Detail

      • getHeaders

        public org.springframework.http.HttpHeaders getHeaders​(javax.servlet.http.HttpServletRequest request)
        Create HttpHeaders for the request.
      • getHeaders

        public org.springframework.http.HttpHeaders getHeaders​(javax.servlet.http.HttpServletResponse response)
        Create HttpHeaders for the response.
      • createRequestLine

        public String createRequestLine​(String request,
                                        String protocol)
        Create a request line for the requestUri and protocol.

        For example: GET /doc/test.html HTTP/1.1.

      • createLogString

        public String createLogString​(org.springframework.http.HttpHeaders headers,
                                      String body)
        Create a log string for the given headers and body with the platform's default charset.
      • createLogString

        public String createLogString​(org.springframework.http.HttpHeaders headers,
                                      byte[] body)
        Create a log string for the given headers and body with the platform's default charset.
      • createLogString

        public String createLogString​(org.springframework.http.HttpHeaders headers,
                                      byte[] body,
                                      String characterEncoding)
        Create a log string for the given headers and body with the given characterEncoding.
      • createLogString

        public String createLogString​(org.springframework.http.HttpHeaders headers,
                                      byte[] body,
                                      Charset charset)
        Create a log string for the given headers and body with the given charset.
      • createLogString

        public String createLogString​(String requestLine,
                                      org.springframework.http.HttpHeaders headers,
                                      byte[] body,
                                      String characterEncoding)
        Create a log string for the given requestLine, headers and body.
      • createLogString

        public String createLogString​(String requestLine,
                                      org.springframework.http.HttpHeaders headers,
                                      byte[] body,
                                      Charset charset)
        Create a log string for the given requestLine, headers and body.
      • createLogString

        public String createLogString​(String requestLine,
                                      org.springframework.http.HttpHeaders headers,
                                      String body)
        Create a log string for the given requestLine, headers and body.
      • getRequestUri

        public String getRequestUri​(javax.servlet.http.HttpServletRequest servletRequest)
        Transform the request into a log line.
      • formatRequest

        public String formatRequest​(String request,
                                    javax.servlet.http.HttpServletRequest servletRequest)
                             throws IOException
        Format the request as a nicely formatted string.

        Note that this will read the request! Use ResettableHttpServletRequest for instance to reset the input.

        Throws:
        IOException