Class HeaderUtils
java.lang.Object
org.glassfish.jersey.message.internal.HeaderUtils
Utility class supporting the processing of message headers.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
asHeaderString
(List<Object> values, javax.ws.rs.ext.RuntimeDelegate rd) Converts a list of message header values to a single string value (with individual values separated by','
).static String
Convert a message header value, represented as a general object, to it's string representation.asStringHeaders
(javax.ws.rs.core.MultivaluedMap<String, Object> headers) Returns string view of passed headers.asStringHeadersSingleValue
(javax.ws.rs.core.MultivaluedMap<String, Object> headers) Transforms multi value map of headers to singleString
value map.asStringList
(List<Object> headerValues, javax.ws.rs.ext.RuntimeDelegate rd) Returns string view of list of header values.static void
checkHeaderChanges
(Map<String, String> headersSnapshot, javax.ws.rs.core.MultivaluedMap<String, Object> currentHeaders, String connectorName) Compares two snapshots of headers from jerseyClientRequest
and logsWARNING
in case of difference.Create an empty inbound message headers container.Create an empty outbound message headers container.static <V> javax.ws.rs.core.MultivaluedMap
<String, V> empty()
Get immutable empty message headers container.
-
Field Details
-
LOGGER
-
-
Constructor Details
-
HeaderUtils
private HeaderUtils()Preventing instantiation.
-
-
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
to convert the value to aString
. If aRuntimeDelegate.HeaderDelegate
is not 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
.
-
asStringList
public static List<String> asStringList(List<Object> headerValues, javax.ws.rs.ext.RuntimeDelegate rd) 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.
-
asStringHeaders
public static javax.ws.rs.core.MultivaluedMap<String,String> asStringHeaders(javax.ws.rs.core.MultivaluedMap<String, Object> headers) 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
.
-
asStringHeadersSingleValue
public static Map<String,String> asStringHeadersSingleValue(javax.ws.rs.core.MultivaluedMap<String, Object> headers) Transforms multi value map of headers to singleString
value map. Returned map is immutable. Map values are formatted using methodasHeaderString(java.util.List<java.lang.Object>, javax.ws.rs.ext.RuntimeDelegate)
.- Parameters:
headers
- headers to be formatted- 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, javax.ws.rs.core.MultivaluedMap<String, Object> currentHeaders, String connectorName) 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:
-