Class HttpMessageUtils

java.lang.Object
org.apache.maven.wagon.shared.http.HttpMessageUtils

public class HttpMessageUtils extends 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 in 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 in 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
  • Field Details

    • UNKNOWN_STATUS_CODE

      public static final int UNKNOWN_STATUS_CODE
      A HTTP status code used to indicate that the actual response status code is not known at time of message generation.
      See Also:
  • Constructor Details

    • HttpMessageUtils

      public HttpMessageUtils()
  • Method Details

    • formatTransferDebugMessage

      public static String formatTransferDebugMessage(String url, int statusCode, String reasonPhrase, org.apache.maven.wagon.proxy.ProxyInfo proxyInfo)
      Format a consistent HTTP transfer debug message combining URL, status code, 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 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:
      NullPointerException - if url is null
    • formatTransferFailedMessage

      public static String formatTransferFailedMessage(String url, org.apache.maven.wagon.proxy.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 String formatTransferFailedMessage(String url, int statusCode, String reasonPhrase, org.apache.maven.wagon.proxy.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 String formatAuthorizationMessage(String url, int statusCode, String reasonPhrase, org.apache.maven.wagon.proxy.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 String formatResourceDoesNotExistMessage(String url, int statusCode, String reasonPhrase, org.apache.maven.wagon.proxy.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