private MultivaluedMap<String, Object> prepareResponseHeaders(Message message,
ResponseImpl response,
Object entity,
boolean firstTry) {
MultivaluedMap<String, Object> responseHeaders = response.getMetadata();
@SuppressWarnings("unchecked")
Map<String, List<Object>> userHeaders = (Map<String, List<Object>>)message.get(Message.PROTOCOL_HEADERS);
if (firstTry && userHeaders != null) {
responseHeaders.putAll(userHeaders);
}
if (entity != null) {
Object customContentType = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
if (customContentType == null) {
String initialResponseContentType = (String)message.get(Message.CONTENT_TYPE);
if (initialResponseContentType != null) {
responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, initialResponseContentType);
}
} else {
message.put(Message.CONTENT_TYPE, customContentType.toString());
}
}
message.put(Message.PROTOCOL_HEADERS, responseHeaders);
setResponseDate(responseHeaders, firstTry);
return responseHeaders;
}