I need support for UTF-8 for my project. I'm hacking around it by the doing the following (not sure all of this is needed):
I needed to return utf-8 json response so I hacked together the following fix. I'm sure there is probably a better way to do this and this may not solve updating a utf-8 response via the UI (header.js hardcodes the character encoding so it will probably mess up UTF-8 responses when displaying and updating responses).
Also the code for detecting the charset and extracting formt he content-type header could probably be a little more robust I guess.
//check content type for charset and try to use that if its there...
//example: application/json;charset=utf-8
//should use the charset "utf-8"
String charSet=HTTP.ISO_8859_1;
try {
if(service.getHttpContentType()!=null) {
final String contentTypeUpper=service.getHttpContentType().toLowerCase();
int charsetIndex=contentTypeUpper.indexOf("charset=");
if(charsetIndex>=0) {
charSet=contentTypeUpper.substring(charsetIndex+"charset=".length());
//make sure it is a valid charset
Charset.forName(charSet);
}
}
} catch(Exception e) {
charSet=HTTP.ISO_8859_1;
}
resp.setCharacterEncoding(charSet); // "UTF-8");
resp.setContentType(service.getHttpContentType());
if (!(service.getServiceResponseType() == Service.SERVICE_RESPONSE_TYPE_PROXY)) {
resp.setContentType(service.getHttpContentType());
byte[] myCharSetBytes = response.getBody().getBytes(charSet);
new PrintStream(resp.getOutputStream()).write(myCharSetBytes);
resp.getOutputStream().flush();
} else {
resp.setStatus(response.getStatusLine().getStatusCode());
response.writeToOutput(resp);
}