IllegalStateException
if called outside the scope of a request (e.g. from a provider constructor).- Since:
- 1.0
- Author:
- Paul Sandoz, Marc Hadley
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
See IETF RFC-2183.static final String
static final String
See IETF RFC-2392.static final String
static final String
static final String
static final String
static final String
See IETF RFC 2109.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
"Last-Event-ID"
HTTP request header name as defined by SSE specification.static final String
static final String
static final String
static final String
static final String
See IETF RFC 2109.static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsHeaderString
(String name, String valueSeparatorRegex, Predicate<String> valuePredicate) Checks whether a header with a specific name and value (or item of the token-separated value list) exists.default boolean
containsHeaderString
(String name, Predicate<String> valuePredicate) Checks whether a header with a specific name and value (or item of the comma-separated value list) exists.Get a list of languages that are acceptable for the response.Get a list of media types that are acceptable for the response.Get any cookies that accompanied the request.getDate()
Get message date.getHeaderString
(String name) Get a HTTP header as a single string value.Get the language of the request entity.int
Get Content-Length value.Get the media type of the request entity.getRequestHeader
(String name) Get the values of a HTTP request header if the header exists on the current request.Get the values of HTTP request headers.
-
Field Details
-
ACCEPT
- See Also:
-
ACCEPT_CHARSET
- See Also:
-
ACCEPT_ENCODING
- See Also:
-
ACCEPT_LANGUAGE
- See Also:
-
ALLOW
- See Also:
-
AUTHORIZATION
- See Also:
-
CACHE_CONTROL
- See Also:
-
CONTENT_DISPOSITION
See IETF RFC-2183.- See Also:
-
CONTENT_ENCODING
- See Also:
-
CONTENT_ID
See IETF RFC-2392.- See Also:
-
CONTENT_LANGUAGE
- See Also:
-
CONTENT_LENGTH
- See Also:
-
CONTENT_LOCATION
- See Also:
-
CONTENT_TYPE
- See Also:
-
DATE
- See Also:
-
ETAG
- See Also:
-
EXPECT
- See Also:
-
EXPIRES
- See Also:
-
HOST
- See Also:
-
IF_MATCH
- See Also:
-
IF_MODIFIED_SINCE
- See Also:
-
IF_NONE_MATCH
- See Also:
-
IF_UNMODIFIED_SINCE
- See Also:
-
LAST_MODIFIED
- See Also:
-
LOCATION
- See Also:
-
LINK
- See Also:
-
RETRY_AFTER
- See Also:
-
USER_AGENT
- See Also:
-
VARY
- See Also:
-
WWW_AUTHENTICATE
- See Also:
-
COOKIE
See IETF RFC 2109.- See Also:
-
SET_COOKIE
See IETF RFC 2109.- See Also:
-
LAST_EVENT_ID_HEADER
"Last-Event-ID"
HTTP request header name as defined by SSE specification.- Since:
- 2.1
- See Also:
-
-
Method Details
-
getRequestHeader
Get the values of a HTTP request header if the header exists on the current request. The returned value will be a read-only List if the specified header exists ornull
if it does not. This is a shortcut forgetRequestHeaders().get(name)
.- Parameters:
name
- the header name, case insensitive.- Returns:
- a read-only list of header values if the specified header exists, otherwise
null
. - Throws:
IllegalStateException
- if called outside the scope of a request.
-
getHeaderString
Get a HTTP header as a single string value.
Each single non-string header value is converted to String using aRuntimeDelegate.HeaderDelegate
if one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the header value class or using itstoString
method if a header delegate is not available.- Parameters:
name
- the HTTP header.- Returns:
- the HTTP header value. If the HTTP header is not present then
null
is returned. If the HTTP header is present but has no value then the empty string is returned. If the HTTP header is present more than once then the values of joined together and separated by a ',' character. - Since:
- 2.0
- See Also:
-
containsHeaderString
boolean containsHeaderString(String name, String valueSeparatorRegex, Predicate<String> valuePredicate) Checks whether a header with a specific name and value (or item of the token-separated value list) exists. Each single non-string header value is converted to String using aRuntimeDelegate.HeaderDelegate
if one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the header value class or using itstoString
method if a header delegate is not available.For example:
containsHeaderString("cache-control", ",", "no-store"::equalsIgnoreCase)
will returntrue
if aCache-Control
header exists that has the valueno-store
, the valueNo-Store
or the valueMax-Age, NO-STORE, no-transform
, butfalse
when it has the valueno-store;no-transform
(missing comma), or the valueno - store
(whitespace within value).- Parameters:
name
- the message header.valueSeparatorRegex
- Separates the header value into single values.null
does not split.valuePredicate
- value must fulfil this predicate.- Returns:
true
if and only if a header with the given name exists, having either a whitespace-trimmed value matching the predicate, or having at least one whitespace-trimmed single value in a token-separated list of single values.- Since:
- 4.0
- See Also:
-
containsHeaderString
Checks whether a header with a specific name and value (or item of the comma-separated value list) exists. Each single non-string header value is converted to String using aRuntimeDelegate.HeaderDelegate
if one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the header value class or using itstoString
method if a header delegate is not available.For example:
containsHeaderString("cache-control", "no-store"::equalsIgnoreCase)
will returntrue
if aCache-Control
header exists that has the valueno-store
, the valueNo-Store
or the valueMax-Age, NO-STORE, no-transform
, butfalse
when it has the valueno-store;no-transform
(missing comma), or the valueno - store
(whitespace within value).- Parameters:
name
- the message header.valuePredicate
- value must fulfil this predicate.- Returns:
true
if and only if a header with the given name exists, having either a whitespace-trimmed value matching the predicate, or having at least one whitespace-trimmed single value in a comma-separated list of single values.- Since:
- 4.0
- See Also:
-
getRequestHeaders
MultivaluedMap<String,String> getRequestHeaders()Get the values of HTTP request headers. The returned Map is case-insensitive wrt. keys and is read-only. The method never returnsnull
.- Returns:
- a read-only map of header names and values.
- Throws:
IllegalStateException
- if called outside the scope of a request.
-
getAcceptableMediaTypes
Get a list of media types that are acceptable for the response.
If no acceptable media types are specified, a read-only list containing a singlewildcard media type
instance is returned.- Returns:
- a read-only list of requested response media types sorted according to their q-value, with highest preference first.
- Throws:
IllegalStateException
- if called outside the scope of a request.
-
getAcceptableLanguages
Get a list of languages that are acceptable for the response.
If no acceptable languages are specified, a read-only list containing a single wildcardLocale
instance (with language field set to "*
") is returned.- Returns:
- a read-only list of acceptable languages sorted according to their q-value, with highest preference first.
- Throws:
IllegalStateException
- if called outside the scope of a request.
-
getMediaType
MediaType getMediaType()Get the media type of the request entity.- Returns:
- the media type or
null
if there is no request entity. - Throws:
IllegalStateException
- if called outside the scope of a request.
-
getLanguage
Locale getLanguage()Get the language of the request entity.- Returns:
- the language of the entity or
null
if not specified. - Throws:
IllegalStateException
- if called outside the scope of a request.
-
getCookies
Get any cookies that accompanied the request.- Returns:
- a read-only map of cookie name (String) to Cookie.
- Throws:
IllegalStateException
- if called outside the scope of a request
-
getDate
Date getDate()Get message date.- Returns:
- the message date, otherwise
null
if not present. - Since:
- 2.0
-
getLength
int getLength()Get Content-Length value.- Returns:
- Content-Length as integer if present and valid number. In other cases returns -1.
- Since:
- 2.0
-