Class MessageHeaderMethods
- Direct Known Subclasses:
InboundMessageContext
,OutboundMessageContext
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
MessageHeaderMethods
(Configuration configuration) protected
-
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.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.protected HeaderValueException
Get the allowed HTTP methods from the Allow HTTP header.getDate()
Get message date.Get the entity tag.abstract MultivaluedMap<String,
?> Get the mutable message headers multivalued map.abstract String
getHeaderString
(String name) Get a message header as a single string value.protected abstract HeaderValueException.Context
ReturnHeaderValueException.Context
type of the message context.Get the language of the entity.Get the last modified date.int
Get Content-Length value.long
Get Content-Length value.Get the link for the relation.getLinkBuilder
(String relation) Convenience method that returns aLink.Builder
for the relation.getLinks()
Get the links attached to the message as header.Get the location.Get any cookies that accompanied the message.Get any new cookies set on the message.boolean
Check if link for relation exists.protected <T> T
singleHeader
(String name, Class<T> valueType, Function<String, T> converter, boolean convertNull) Get a single typed header value.protected <T> T
singleHeader
(String name, Function<String, T> converter, boolean convertNull) Get a single typed header value for Inbound messages
-
Field Details
-
runtimeDelegateDecorator
-
-
Constructor Details
-
MessageHeaderMethods
-
MessageHeaderMethods
-
-
Method Details
-
getHeaderString
Get a message 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 message header.- Returns:
- the message header value. If the message header is not present then
null
is returned. If the message header is present but has no value then the empty string is returned. If the message header is present more than once then the values of joined together and separated by a ',' character.
-
getHeaders
Get the mutable message headers multivalued map.- Returns:
- mutable multivalued map of message headers.
-
getHeaderValueExceptionContext
ReturnHeaderValueException.Context
type of the message context.- Returns:
HeaderValueException.Context
type of the message context.
-
getLinks
Get the links attached to the message as header.- Returns:
- links, may return empty
Set
if no links are present. Never returnsnull
.
-
containsHeaderString
public 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.
-
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.
-
getAllowedMethods
Get the allowed HTTP methods from the Allow HTTP header.- Returns:
- the allowed HTTP methods, all methods will returned as upper case strings.
-
getDate
Get message date.- Returns:
- the message date, otherwise
null
if not present.
-
getEntityTag
Get the entity tag.- Returns:
- the entity tag, otherwise
null
if not present.
-
getLanguage
Get the language of the entity.- Returns:
- the language of the entity or
null
if not specified
-
getLastModified
Get the last modified date.- Returns:
- the last modified date, otherwise
null
if not present.
-
getLength
public int getLength()Get Content-Length value.Note:
getLengthLong()
should be preferred over this method, since it returns along
instead and is therefore more portable.- Returns:
- Content-Length as a postive integer if present and valid number,
-1
if negative number. - Throws:
ProcessingException
- whenInteger.parseInt(String)
(String)} throwsNumberFormatException
.
-
getLengthLong
public long getLengthLong()Get Content-Length value.- Returns:
- Content-Length as a positive long if present and valid number,
-1
if negative number. - Throws:
ProcessingException
- whenLong.parseLong(String)
throwsNumberFormatException
.
-
getLink
Get the link for the relation.- Parameters:
relation
- link relation.- Returns:
- the link for the relation, otherwise
null
if not present.
-
getLinkBuilder
Convenience method that returns aLink.Builder
for the relation.- Parameters:
relation
- link relation.- Returns:
- the link builder for the relation, otherwise
null
if not present.
-
getLocation
Get the location.- Returns:
- the location URI, otherwise
null
if not present.
-
getRequestCookies
Get any cookies that accompanied the message.- Returns:
- a read-only map of cookie name (String) to
Cookie
.
-
getResponseCookies
Get any new cookies set on the message.- Returns:
- a read-only map of cookie name (String) to a
new cookie
.
-
hasLink
Check if link for relation exists.- Parameters:
relation
- link relation.- Returns:
true
if the for the relation link exists,false
otherwise.
-
singleHeader
protected <T> T singleHeader(String name, Class<T> valueType, Function<String, T> converter, boolean convertNull) Get a single typed header value.- Type Parameters:
T
- header value type.- Parameters:
name
- header name.valueType
- header value class.converter
- from string conversion function. Is expected to throwProcessingException
if conversion fails.convertNull
- iftrue
this method calls the provided converter even fornull
. Otherwise this method returns thenull
without calling the converter.- Returns:
- value of the header, or (possibly converted)
null
if not present.
-
singleHeader
Get a single typed header value for Inbound messages- Type Parameters:
T
- header value type.- Parameters:
name
- header name.converter
- from string conversion function. Is expected to throwProcessingException
if conversion fails.convertNull
- iftrue
this method calls the provided converter even fornull
. Otherwise this method returns thenull
without calling the converter.- Returns:
- value of the header, or (possibly converted)
null
if not present.
-
exception
-