Class MessageHeaderMethods
- Direct Known Subclasses:
InboundMessageContext,OutboundMessageContext
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMessageHeaderMethods(Configuration configuration) protected -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsHeaderString(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.booleancontainsHeaderString(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 HeaderValueExceptionGet 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 StringgetHeaderString(String name) Get a message header as a single string value.protected abstract HeaderValueException.ContextReturnHeaderValueException.Contexttype of the message context.Get the language of the entity.Get the last modified date.intGet Content-Length value.longGet Content-Length value.Get the link for the relation.getLinkBuilder(String relation) Convenience method that returns aLink.Builderfor 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.booleanCheck if link for relation exists.protected <T> TsingleHeader(String name, Class<T> valueType, Function<String, T> converter, boolean convertNull) Get a single typed header value.protected <T> TsingleHeader(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.HeaderDelegateif one is available viaRuntimeDelegate#createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod 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
nullis 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.Contexttype of the message context.- Returns:
HeaderValueException.Contexttype of the message context.
-
getLinks
Get the links attached to the message as header.- Returns:
- links, may return empty
Setif 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.HeaderDelegateif one is available viaRuntimeDelegate#createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod if a header delegate is not available.For example:
containsHeaderString("cache-control", ",", "no-store"::equalsIgnoreCase)will returntrueif aCache-Controlheader exists that has the valueno-store, the valueNo-Storeor the valueMax-Age, NO-STORE, no-transform, butfalsewhen 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.nulldoes not split.valuePredicate- value must fulfil this predicate.- Returns:
trueif 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.HeaderDelegateif one is available viaRuntimeDelegate#createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod if a header delegate is not available.For example:
containsHeaderString("cache-control", "no-store"::equalsIgnoreCase)will returntrueif aCache-Controlheader exists that has the valueno-store, the valueNo-Storeor the valueMax-Age, NO-STORE, no-transform, butfalsewhen 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:
trueif 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
nullif not present.
-
getEntityTag
Get the entity tag.- Returns:
- the entity tag, otherwise
nullif not present.
-
getLanguage
Get the language of the entity.- Returns:
- the language of the entity or
nullif not specified
-
getLastModified
Get the last modified date.- Returns:
- the last modified date, otherwise
nullif not present.
-
getLength
public int getLength()Get Content-Length value.Note:
getLengthLong()should be preferred over this method, since it returns alonginstead and is therefore more portable.- Returns:
- Content-Length as a postive integer if present and valid number,
-1if 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,
-1if 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
nullif not present.
-
getLinkBuilder
Convenience method that returns aLink.Builderfor the relation.- Parameters:
relation- link relation.- Returns:
- the link builder for the relation, otherwise
nullif not present.
-
getLocation
Get the location.- Returns:
- the location URI, otherwise
nullif 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:
trueif the for the relation link exists,falseotherwise.
-
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 throwProcessingExceptionif conversion fails.convertNull- iftruethis method calls the provided converter even fornull. Otherwise this method returns thenullwithout calling the converter.- Returns:
- value of the header, or (possibly converted)
nullif 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 throwProcessingExceptionif conversion fails.convertNull- iftruethis method calls the provided converter even fornull. Otherwise this method returns thenullwithout calling the converter.- Returns:
- value of the header, or (possibly converted)
nullif not present.
-
exception
-