Class HttpMessageUtils
- java.lang.Object
-
- org.apache.maven.wagon.shared.http.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 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..
- Since:
- 3.3.4
-
-
Field Summary
Fields Modifier and Type Field Description private static int
SC_FORBIDDEN
private static int
SC_GONE
private static int
SC_NOT_FOUND
private static int
SC_PROXY_AUTH_REQUIRED
private static int
SC_UNAUTHORIZED
static 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.
-
Constructor Summary
Constructors Constructor Description HttpMessageUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
formatAuthorizationMessage(java.lang.String url, int statusCode, java.lang.String reasonPhrase, ProxyInfo proxyInfo)
Format a consistent message for HTTP relatedAuthorizationException
.private static java.lang.String
formatMessage(java.lang.String message, java.lang.String url, int statusCode, java.lang.String reasonPhrase, ProxyInfo proxyInfo)
static java.lang.String
formatResourceDoesNotExistMessage(java.lang.String url, int statusCode, java.lang.String reasonPhrase, ProxyInfo proxyInfo)
Format a consistent message for HTTP relatedResourceDoesNotExistException
.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, reason phrase and HTTP proxy server info.static java.lang.String
formatTransferFailedMessage(java.lang.String url, int statusCode, java.lang.String reasonPhrase, ProxyInfo proxyInfo)
Format a consistent message for HTTP relatedTransferFailedException
.static java.lang.String
formatTransferFailedMessage(java.lang.String url, ProxyInfo proxyInfo)
Format a consistent message for HTTP relatedTransferFailedException
.
-
-
-
Field Detail
-
SC_UNAUTHORIZED
private static final int SC_UNAUTHORIZED
- See Also:
- Constant Field Values
-
SC_FORBIDDEN
private static final int SC_FORBIDDEN
- See Also:
- Constant Field Values
-
SC_NOT_FOUND
private static final int SC_NOT_FOUND
- See Also:
- Constant Field Values
-
SC_PROXY_AUTH_REQUIRED
private static final int SC_PROXY_AUTH_REQUIRED
- See Also:
- Constant Field Values
-
SC_GONE
private static final int SC_GONE
- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
-
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, 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 notUNKNOWN_STATUS_CODE
. Proxy information will only be included if not null.- Parameters:
url
- the required non-null URL associated with the messagestatusCode
- an HTTP response status codereasonPhrase
- an HTTP reason phraseproxyInfo
- 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 relatedTransferFailedException
.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)
withUNKNOWN_STATUS_CODE
and null reason phrase.- Parameters:
url
- the URL associated with the messageproxyInfo
- 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 relatedTransferFailedException
.- Parameters:
url
- the URL associated with the messagestatusCode
- an HTTP response status code orUNKNOWN_STATUS_CODE
reasonPhrase
- an HTTP status line reason phrase or null if the reason phrase unknownproxyInfo
- 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 relatedAuthorizationException
.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 messagestatusCode
- an HTTP response status code related to authreasonPhrase
- an HTTP status line reason phraseproxyInfo
- 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 relatedResourceDoesNotExistException
.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 messagestatusCode
- an HTTP response status code related to resources not being foundreasonPhrase
- an HTTP status line reason phraseproxyInfo
- 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)
-
-