public MediaType setDefaultCharsetOnMediaTypeHeader(MultivaluedMap<String, Object> httpHeaders,
MediaType mediaType) {
logger.trace("setDefaultCharsetOnMediaTypeHeader({}, {}) entry", httpHeaders, mediaType); //$NON-NLS-1$
RuntimeContext context = RuntimeContextTLS.getRuntimeContext();
// we're on the server, so this is a safe cast
DeploymentConfiguration config = (DeploymentConfiguration)context.getAttribute(WinkConfiguration.class);
if (config.isDefaultResponseCharset() || config.isUseAcceptCharset()) {
if (httpHeaders != null && (httpHeaders.isEmpty() || httpHeaders
.get(HttpHeaders.CONTENT_TYPE) == null)) {
// only correct the MediaType if the MediaType was not explicitly
// set
logger.trace("Media Type not explicitly set on Response so going to correct charset parameter if necessary"); //$NON-NLS-1$
if (ProviderUtils.getCharsetOrNull(mediaType) == null) { //$NON-NLS-1$
try {
String charsetValue = "UTF-8"; //$NON-NLS-1$
if (config.isUseAcceptCharset()) {
// configuration says to inspect and use the Accept-Charset header to determine response charset
HttpHeaders requestHeaders = null;
if (context != null) {
requestHeaders = context.getHttpHeaders();
}
charsetValue = ProviderUtils.getCharset(mediaType, requestHeaders);
}
String newMediaTypeStr = mediaType.toString() + ";charset=" + charsetValue; //$NON-NLS-1$
mediaType = MediaType.valueOf(newMediaTypeStr);