Class HttpRequestUtils


  • public class HttpRequestUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getPostDataAsString​(jakarta.servlet.http.HttpServletRequest request)
      Reads the POST data from a request into a String and returns it.
      static java.lang.String getReaderContentAsString​(java.io.Reader reader)
      Reads the content of a Reader instance and returns it as a String.
      static java.lang.String getRequestDump​(java.lang.String fromMethod, jakarta.servlet.http.HttpServletRequest request, boolean includePostData)
      Build a String containing a multi-line dump of an HTTP request.
      static java.lang.String getShortRequestDump​(java.lang.String fromMethod, boolean includeHeaders, jakarta.servlet.http.HttpServletRequest request)
      Build a String containing a short multi-line dump of an HTTP request.
      static java.lang.String getShortRequestDump​(java.lang.String fromMethod, jakarta.servlet.http.HttpServletRequest request)
      Build a String containing a very short multi-line dump of an HTTP request.
      static java.lang.String maskPrivateToken​(java.lang.String s)
      Masks the PRIVATE-TOKEN header value with "********".
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpRequestUtils

        public HttpRequestUtils()
    • Method Detail

      • getShortRequestDump

        public static java.lang.String getShortRequestDump​(java.lang.String fromMethod,
                                                           jakarta.servlet.http.HttpServletRequest request)
        Build a String containing a very short multi-line dump of an HTTP request.
        Parameters:
        fromMethod - the method that this method was called from
        request - the HTTP request build the request dump from
        Returns:
        a String containing a very short multi-line dump of the HTTP request
      • getShortRequestDump

        public static java.lang.String getShortRequestDump​(java.lang.String fromMethod,
                                                           boolean includeHeaders,
                                                           jakarta.servlet.http.HttpServletRequest request)
        Build a String containing a short multi-line dump of an HTTP request.
        Parameters:
        fromMethod - the method that this method was called from
        request - the HTTP request build the request dump from
        includeHeaders - if true will include the HTTP headers in the dump
        Returns:
        a String containing a short multi-line dump of the HTTP request
      • getRequestDump

        public static java.lang.String getRequestDump​(java.lang.String fromMethod,
                                                      jakarta.servlet.http.HttpServletRequest request,
                                                      boolean includePostData)
        Build a String containing a multi-line dump of an HTTP request.
        Parameters:
        fromMethod - the method that this method was called from
        request - the HTTP request build the request dump from
        includePostData - if true will include the POST data in the dump
        Returns:
        a String containing a multi-line dump of the HTTP request, If an error occurs, the message from the exception will be returned
      • getPostDataAsString

        public static java.lang.String getPostDataAsString​(jakarta.servlet.http.HttpServletRequest request)
                                                    throws java.io.IOException
        Reads the POST data from a request into a String and returns it.
        Parameters:
        request - the HTTP request containing the POST data
        Returns:
        the POST data as a String instance
        Throws:
        java.io.IOException - if any error occurs while reading the POST data
      • getReaderContentAsString

        public static java.lang.String getReaderContentAsString​(java.io.Reader reader)
                                                         throws java.io.IOException
        Reads the content of a Reader instance and returns it as a String.
        Parameters:
        reader - the Reader instance to read the data from
        Returns:
        the content of a Reader instance as a String
        Throws:
        java.io.IOException - if any error occurs while reading the POST data
      • maskPrivateToken

        public static java.lang.String maskPrivateToken​(java.lang.String s)
        Masks the PRIVATE-TOKEN header value with "********".
        Parameters:
        s - a String containing HTTP request info, usually logging info
        Returns:
        a String with the PRIVATE-TOKEN header value masked with asterisks