public final class HeaderUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
LOGGER |
Modifier | Constructor and Description |
---|---|
private |
HeaderUtils()
Preventing instantiation.
|
Modifier and Type | Method and Description |
---|---|
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
',' ). |
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.
|
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 single
String value 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 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 jersey
ClientRequest and logs WARNING in 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.
|
public static javax.ws.rs.core.AbstractMultivaluedMap<java.lang.String,java.lang.String> createInbound()
public static <V> javax.ws.rs.core.MultivaluedMap<java.lang.String,V> empty()
V
- header value type. Typically Object
in case of the outbound
headers and String
in case of the inbound headers.public static javax.ws.rs.core.AbstractMultivaluedMap<java.lang.String,java.lang.Object> createOutbound()
public static java.lang.String asString(java.lang.Object headerValue, javax.ws.rs.ext.RuntimeDelegate rd)
null
,
this method returns null
.
This method defers to RuntimeDelegate.createHeaderDelegate(java.lang.Class<T>)
to
obtain a RuntimeDelegate.HeaderDelegate
to convert the value to a String
.
If a RuntimeDelegate.HeaderDelegate
is not found then the toString()
method on the header object is utilized.
headerValue
- the header value represented as an object.rd
- runtime delegate instance to be used for header delegate
retrieval. If null
, a default RuntimeDelegate
instance will be obtained
and
used.null
if the supplied header value is null
.public static java.util.List<java.lang.String> asStringList(java.util.List<java.lang.Object> headerValues, javax.ws.rs.ext.RuntimeDelegate rd)
headerValues
- header values.rd
- RuntimeDelegate instance or null
(in that case RuntimeDelegate.getInstance()
will be called for before element conversion.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)
headers
- headers.null
if {code headers} input parameter is null
.public static java.util.Map<java.lang.String,java.lang.String> asStringHeadersSingleValue(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers)
String
value map.
Returned map is immutable. Map values are formatted using method asHeaderString(java.util.List<java.lang.Object>, javax.ws.rs.ext.RuntimeDelegate)
.headers
- headers to be formattedString
value map or
null
if headers
input parameter is null
.public static java.lang.String asHeaderString(java.util.List<java.lang.Object> values, javax.ws.rs.ext.RuntimeDelegate rd)
','
).
Each single header value is converted to String using a
RuntimeDelegate.HeaderDelegate
if one is available
via RuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the header value class or using its toString()
method if a header
delegate is not available.values
- list of individual header values.rd
- RuntimeDelegate
instance or null
(in that case RuntimeDelegate.getInstance()
will be called for before conversion of elements).null
,
null
is returned. If the list of values is empty, an empty string is returned.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)
ClientRequest
and logs WARNING
in case of difference.
Current container implementations does not support header modification in WriterInterceptor
and MessageBodyWriter
. The method checks there are some newly added headers
(probably by WI or MBW) and logs WARNING
message about it.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