Class HeaderUtils
- java.lang.Object
-
- org.glassfish.jersey.message.internal.HeaderUtils
-
public final class HeaderUtils extends java.lang.ObjectUtility class supporting the processing of message headers.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.LoggerLOGGER
-
Constructor Summary
Constructors Modifier Constructor Description privateHeaderUtils()Preventing instantiation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringasHeaderString(java.util.List<java.lang.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 java.lang.StringasString(java.lang.Object headerValue, javax.ws.rs.ext.RuntimeDelegate rd)Convert a message header value, represented as a general object, to it's string representation.static javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>asStringHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers)Returns string view of passed headers.static java.util.Map<java.lang.String,java.lang.String>asStringHeadersSingleValue(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers)Transforms multi value map of headers to singleStringvalue map.static java.util.List<java.lang.String>asStringList(java.util.List<java.lang.Object> headerValues, javax.ws.rs.ext.RuntimeDelegate rd)Returns string view of list of header values.static voidcheckHeaderChanges(java.util.Map<java.lang.String,java.lang.String> headersSnapshot, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> currentHeaders, java.lang.String connectorName)Compares two snapshots of headers from jerseyClientRequestand logsWARNINGin case of difference.static javax.ws.rs.core.AbstractMultivaluedMap<java.lang.String,java.lang.String>createInbound()Create an empty inbound message headers container.static javax.ws.rs.core.AbstractMultivaluedMap<java.lang.String,java.lang.Object>createOutbound()Create an empty outbound message headers container.static <V> javax.ws.rs.core.MultivaluedMap<java.lang.String,V>empty()Get immutable empty message headers container.
-
-
-
Method Detail
-
createInbound
public static javax.ws.rs.core.AbstractMultivaluedMap<java.lang.String,java.lang.String> createInbound()
Create an empty inbound message headers container. Created container is mutable.- Returns:
- a new empty mutable container for storing inbound message headers.
-
empty
public static <V> javax.ws.rs.core.MultivaluedMap<java.lang.String,V> 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.- Type Parameters:
V- header value type. TypicallyObjectin case of the outbound headers andStringin case of the inbound headers.- Returns:
- an immutable empty message headers container.
-
createOutbound
public static javax.ws.rs.core.AbstractMultivaluedMap<java.lang.String,java.lang.Object> createOutbound()
Create an empty outbound message headers container. Created container is mutable.- Returns:
- a new empty mutable container for storing outbound message headers.
-
asString
public static java.lang.String asString(java.lang.Object headerValue, javax.ws.rs.ext.RuntimeDelegate rd)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.HeaderDelegateto convert the value to aString. If aRuntimeDelegate.HeaderDelegateis 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 defaultRuntimeDelegateinstance will beobtainedand used.- Returns:
- the string representation of the supplied header value or
nullif the supplied header value isnull.
-
asStringList
public static java.util.List<java.lang.String> asStringList(java.util.List<java.lang.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<java.lang.String,java.lang.String> asStringHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.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
nullif {code headers} input parameter isnull.
-
asStringHeadersSingleValue
public static java.util.Map<java.lang.String,java.lang.String> asStringHeadersSingleValue(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers)
Transforms multi value map of headers to singleStringvalue 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
Stringvalue map ornullifheadersinput parameter isnull.
-
asHeaderString
public static java.lang.String asHeaderString(java.util.List<java.lang.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','). Each single header value is converted to String using aRuntimeDelegate.HeaderDelegateif 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-RuntimeDelegateinstance 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,nullis returned. If the list of values is empty, an empty string is returned.
-
checkHeaderChanges
public static void checkHeaderChanges(java.util.Map<java.lang.String,java.lang.String> headersSnapshot, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> currentHeaders, java.lang.String connectorName)Compares two snapshots of headers from jerseyClientRequestand logsWARNINGin case of difference. Current container implementations does not support header modification inWriterInterceptorandMessageBodyWriter. The method checks there are some newly added headers (probably by WI or MBW) and logsWARNINGmessage 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:
- JERSEY-2341
-
-