Class HeaderUtils
java.lang.Object
org.glassfish.jersey.message.internal.HeaderUtils
Utility class supporting the processing of message headers.
- Author:
- Marek Potociar, Michal Gajdos, Libor Kramolis
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
asHeaderString
(List<Object> values, RuntimeDelegate rd) Converts a list of message header values to a single string value (with individual values separated by','
).static String
Deprecated.static String
asString
(Object headerValue, Configuration configuration) Convert a message header value, represented as a general object, to it's string representation.static String
asString
(Object headerValue, RuntimeDelegate rd) Convert a message header value, represented as a general object, to it's string representation.static MultivaluedMap<String,
String> asStringHeaders
(MultivaluedMap<String, Object> headers) Deprecated.static MultivaluedMap<String,
String> asStringHeaders
(MultivaluedMap<String, Object> headers, Configuration configuration) Returns string view of passed headers.static MultivaluedMap<String,
String> asStringHeaders
(MultivaluedMap<String, Object> headers, RuntimeDelegate rd) Returns string view of passed headers.asStringHeadersSingleValue
(MultivaluedMap<String, Object> headers) Deprecated.asStringHeadersSingleValue
(MultivaluedMap<String, Object> headers, Configuration configuration) Transforms multi value map of headers to singleString
value map.asStringList
(List<Object> headerValues) Deprecated.asStringList
(List<Object> headerValues, Configuration configuration) Returns string view of list of header values.asStringList
(List<Object> headerValues, RuntimeDelegate rd) Returns string view of list of header values.static void
checkHeaderChanges
(Map<String, String> headersSnapshot, MultivaluedMap<String, Object> currentHeaders, String connectorName) Deprecated.static void
checkHeaderChanges
(Map<String, String> headersSnapshot, MultivaluedMap<String, Object> currentHeaders, String connectorName, Configuration configuration) Compares two snapshots of headers from jerseyClientRequest
and logsWARNING
in case of difference.static AbstractMultivaluedMap<String,
String> Create an empty inbound message headers container.static AbstractMultivaluedMap<String,
Object> Create an empty outbound message headers container.static <V> MultivaluedMap<String,
V> empty()
Get immutable empty message headers container.static NewCookie
getPreferredCookie
(NewCookie first, NewCookie second) Compare two NewCookies having the same name.
-
Method Details
-
createInbound
Create an empty inbound message headers container. Created container is mutable.- Returns:
- a new empty mutable container for storing inbound message headers.
-
empty
Get immutable empty message headers container. The factory method can be used to for both message header container types – inbound as well as outbound. -
createOutbound
Create an empty outbound message headers container. Created container is mutable.- Returns:
- a new empty mutable container for storing outbound message headers.
-
asString
Convert a message header value, represented as a general object, to it's string representation. If the supplied header value isnull
, this method returnsnull
.This method defers to
RuntimeDelegate.createHeaderDelegate(java.lang.Class<T>)
to obtain aRuntimeDelegate.HeaderDelegate
orHeaderDelegateProvider
to convert the value to aString
. If neither is found then thetoString()
method on the header object is utilized.- Parameters:
headerValue
- the header value represented as an object.rd
- runtime delegate instance to be used for header delegate retrieval. Ifnull
, a defaultRuntimeDelegate
instance will beobtained
and used.- Returns:
- the string representation of the supplied header value or
null
if the supplied header value isnull
.
-
asString
Convert a message header value, represented as a general object, to it's string representation. If the supplied header value isnull
, this method returnsnull
.This method defers to
RuntimeDelegate.createHeaderDelegate(java.lang.Class<T>)
to obtain aRuntimeDelegate.HeaderDelegate
orHeaderDelegateProvider
to convert the value to aString
. If neither is found then thetoString()
method on the header object is utilized.- Parameters:
headerValue
- the header value represented as an object.configuration
- theConfiguration
that may containCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
property preventing theHeaderDelegateProvider
to be used by the defaultRuntimeDelegate
instance
.- Returns:
- the string representation of the supplied header value or
null
if the supplied header value isnull
.
-
asStringList
Returns string view of list of header values. Any modifications to the underlying list are visible to the view, the view also supports removal of elements. Does not support other modifications.- Parameters:
headerValues
- header values.rd
- RuntimeDelegate instance ornull
(in that caseRuntimeDelegate.getInstance()
will be called for before element conversion.- Returns:
- String view of header values.
-
asStringList
Returns string view of list of header values. Any modifications to the underlying list are visible to the view, the view also supports removal of elements. Does not support other modifications.- Parameters:
headerValues
- header values.configuration
- theConfiguration
that may containCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
property preventing theHeaderDelegateProvider
to be used by the defaultRuntimeDelegate
instance
.- Returns:
- String view of header values.
-
asStringHeaders
public static MultivaluedMap<String,String> asStringHeaders(MultivaluedMap<String, Object> headers, Configuration configuration) Returns string view of passed headers. Any modifications to the headers are visible to the view, the view also supports removal of elements. Does not support other modifications.- Parameters:
headers
- headers.configuration
- theConfiguration
that may containCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
property preventing theHeaderDelegateProvider
to be used by the defaultRuntimeDelegate
instance
.- Returns:
- String view of headers or
null
if {code headers} input parameter isnull
.
-
asStringHeaders
public static MultivaluedMap<String,String> asStringHeaders(MultivaluedMap<String, Object> headers, RuntimeDelegate rd) Returns string view of passed headers. Any modifications to the headers are visible to the view, the view also supports removal of elements. Does not support other modifications.- Parameters:
headers
- headers.rd
-RuntimeDelegate
instance ornull
(in that caseRuntimeDelegate.getInstance()
will be called for before conversion of elements).- Returns:
- String view of headers or
null
if {code headers} input parameter isnull
.
-
asStringHeadersSingleValue
public static Map<String,String> asStringHeadersSingleValue(MultivaluedMap<String, Object> headers, Configuration configuration) Transforms multi value map of headers to singleString
value map. Returned map is immutable. Map values are formatted using methodasHeaderString(List, RuntimeDelegate)
.- Parameters:
headers
- headers to be formattedconfiguration
- theConfiguration
that may containCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
property preventing theHeaderDelegateProvider
to be used by the defaultRuntimeDelegate
instance
.- Returns:
- immutable single
String
value map ornull
ifheaders
input parameter isnull
.
-
asHeaderString
Converts a list of message header values to a single string value (with individual values separated by','
). Each single 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:
values
- list of individual header values.rd
-RuntimeDelegate
instance ornull
(in that caseRuntimeDelegate.getInstance()
will be called for before conversion of elements).- Returns:
- single string consisting of all the values passed in as a parameter. If values parameter is
null
,null
is returned. If the list of values is empty, an empty string is returned.
-
checkHeaderChanges
public static void checkHeaderChanges(Map<String, String> headersSnapshot, MultivaluedMap<String, Object> currentHeaders, String connectorName, Configuration configuration) Compares two snapshots of headers from jerseyClientRequest
and logsWARNING
in case of difference. Current container implementations does not support header modification inWriterInterceptor
andMessageBodyWriter
. The method checks there are some newly added headers (probably by WI or MBW) and logsWARNING
message about it.- Parameters:
headersSnapshot
- first immutable snapshot of headerscurrentHeaders
- current instance of headers tobe compared toconnectorName
- name of connector the method is invoked from, used just in logged messageconfiguration
- theConfiguration
that may containCommonProperties.METAINF_SERVICES_LOOKUP_DISABLE
property preventing theHeaderDelegateProvider
to be used by the defaultRuntimeDelegate
instance
.- See Also:
-
getPreferredCookie
Compare two NewCookies having the same name. See documentation RFC.- Parameters:
first
- NewCookie to be compared.second
- NewCookie to be compared.- Returns:
- the preferred NewCookie according to rules : - the latest maxAge. - if equal, compare the expiry date. - if equal, compare path length.
-
asString
Deprecated.Convert a message header value, represented as a general object, to it's string representation. If the supplied header value isnull
, this method returnsnull
.- Parameters:
headerValue
- the header value represented as an object.- Returns:
- the string representation of the supplied header value or
null
if the supplied header value isnull
. - See Also:
-
asStringList
Deprecated.Returns string view of list of header values. Any modifications to the underlying list are visible to the view, the view also supports removal of elements. Does not support other modifications.- Parameters:
headerValues
- header values.- Returns:
- String view of header values.
- See Also:
-
asStringHeaders
@Deprecated public static MultivaluedMap<String,String> asStringHeaders(MultivaluedMap<String, Object> headers) Deprecated.Returns string view of passed headers. Any modifications to the headers are visible to the view, the view also supports removal of elements. Does not support other modifications.- Parameters:
headers
- headers.- Returns:
- String view of headers or
null
if {code headers} input parameter isnull
. - See Also:
-
asStringHeadersSingleValue
@Deprecated public static Map<String,String> asStringHeadersSingleValue(MultivaluedMap<String, Object> headers) Deprecated.Transforms multi value map of headers to singleString
value map. Returned map is immutable. Map values are formatted using methodasHeaderString(List, RuntimeDelegate)
.- Parameters:
headers
- headers to be formatted- Returns:
- immutable single
String
value map ornull
ifheaders
input parameter isnull
. - See Also:
-
checkHeaderChanges
@Deprecated public static void checkHeaderChanges(Map<String, String> headersSnapshot, MultivaluedMap<String, Object> currentHeaders, String connectorName) Deprecated.Compares two snapshots of headers from jerseyClientRequest
and logsWARNING
in case of difference. Current container implementations does not support header modification inWriterInterceptor
andMessageBodyWriter
. The method checks there are some newly added headers (probably by WI or MBW) and logsWARNING
message about it.- Parameters:
headersSnapshot
- first immutable snapshot of headerscurrentHeaders
- current instance of headers tobe compared toconnectorName
- name of connector the method is invoked from, used just in logged message- See Also:
-