Class HttpMessageUtils


  • public class HttpMessageUtils
    extends java.lang.Object
    Helper for HTTP related messages.

    Important notice on Reason Phrase:

    • reason phrase was defined by initial HTTP/1.1 RFC 2616: The Reason-Phrase is intended to give a short textual description of the Status-Code. The Status-Code is intended for use by automata and the Reason-Phrase is intended for the human user. The client is not required to examine or display the Reason- Phrase.
    • it has been later largely deprecated in the updated HTTP/1.1 RFC-7230: The reason-phrase element exists for the sole purpose of providing a textual description associated with the numeric status code, mostly out of deference to earlier Internet application protocols that were more frequently used with interactive text clients. A client SHOULD ignore the reason-phrase content.
    • it has been removed from HTTP/2 RFC 7540: HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line..
    The use of Reason Phrase done here to improve the message to the end-user (particularly in case of failures) will disappear while HTTP/2 is deployed: a new mechanism to provide such a message needs to be defined...
    Since:
    3.3.4
    • Constructor Detail

      • HttpMessageUtils

        public HttpMessageUtils()
    • Method Detail

      • formatTransferDebugMessage

        public static java.lang.String formatTransferDebugMessage​(java.lang.String url,
                                                                  int statusCode,
                                                                  java.lang.String reasonPhrase,
                                                                  ProxyInfo proxyInfo)
        Format a consistent HTTP transfer debug message combining url, status code, status line reason phrase and HTTP proxy server info.

        Url will always be included in the message. A status code other than UNKNOWN_STATUS_CODE will be included. A reason phrase will only be included if non-empty and status code is not UNKNOWN_STATUS_CODE. Proxy information will only be included if not null.

        Parameters:
        url - the required non-null URL associated with the message
        statusCode - an HTTP response status code
        reasonPhrase - an HTTP status line reason phrase
        proxyInfo - proxy server used during the transfer, may be null if none used
        Returns:
        a formatted debug message combining the parameters of this method
        Throws:
        java.lang.NullPointerException - if url is null
      • formatTransferFailedMessage

        public static java.lang.String formatTransferFailedMessage​(java.lang.String url,
                                                                   ProxyInfo proxyInfo)
        Format a consistent message for HTTP related TransferFailedException.

        This variation typically used in cases where there is no HTTP transfer response data to extract status code and reason phrase from. Equivalent to calling formatTransferFailedMessage(String, int, String, ProxyInfo) with UNKNOWN_STATUS_CODE and null reason phrase.

        Parameters:
        url - the URL associated with the message
        proxyInfo - proxy server used during the transfer, may be null if none used
        Returns:
        a formatted failure message combining the parameters of this method
      • formatTransferFailedMessage

        public static java.lang.String formatTransferFailedMessage​(java.lang.String url,
                                                                   int statusCode,
                                                                   java.lang.String reasonPhrase,
                                                                   ProxyInfo proxyInfo)
        Format a consistent message for HTTP related TransferFailedException.
        Parameters:
        url - the URL associated with the message
        statusCode - an HTTP response status code or UNKNOWN_STATUS_CODE
        reasonPhrase - an HTTP status line reason phrase or null if the reason phrase unknown
        proxyInfo - proxy server used during the transfer, may be null if none used
        Returns:
        a formatted failure message combining the parameters of this method
      • formatAuthorizationMessage

        public static java.lang.String formatAuthorizationMessage​(java.lang.String url,
                                                                  int statusCode,
                                                                  java.lang.String reasonPhrase,
                                                                  ProxyInfo proxyInfo)
        Format a consistent message for HTTP related AuthorizationException.

        The message will always include the URL and status code provided. If empty, the reason phrase is substituted with a common reason based on status code. ProxyInfo is only included in the message if not null.

        Parameters:
        url - the URL associated with the message
        statusCode - an HTTP response status code related to auth
        reasonPhrase - an HTTP status line reason phrase
        proxyInfo - proxy server used during the transfer, may be null if none used
        Returns:
        a consistent message for a HTTP related AuthorizationException
      • formatResourceDoesNotExistMessage

        public static java.lang.String formatResourceDoesNotExistMessage​(java.lang.String url,
                                                                         int statusCode,
                                                                         java.lang.String reasonPhrase,
                                                                         ProxyInfo proxyInfo)
        Format a consistent message for HTTP related ResourceDoesNotExistException.

        The message will always include the URL and status code provided. If empty, the reason phrase is substituted with the commonly used reason phrases per status code. ProxyInfo is only included if not null.

        Parameters:
        url - the URL associated with the message
        statusCode - an HTTP response status code related to resources not being found
        reasonPhrase - an HTTP status line reason phrase
        proxyInfo - proxy server used during the transfer, may be null if none used
        Returns:
        a consistent message for a HTTP related ResourceDoesNotExistException
      • formatMessage

        private static java.lang.String formatMessage​(java.lang.String message,
                                                      java.lang.String url,
                                                      int statusCode,
                                                      java.lang.String reasonPhrase,
                                                      ProxyInfo proxyInfo)