Android client, using Springs resttemplace and the Apache common HTTP client to make requests.
I'm working against a server, that sometimes returns a 401 error, with a http header string, "ERROR" that contains a user-info string. The string is language dependent, so it might contain, for example, Scandinavian characters.
The string looks fine in my IOS app, aswell as when i examine it in the Firefox RESTclient plugin.
However, in my Android app, i cannot for the life of me get the chars to come out right. I'd very much appreciate it if someone could think of a way i can make the data come out right.
The server sends content-type UTF-8, and its a regular .setHeader() on the httpservletresponse that sets the parameter i try to retrieve.
Here's the creation of my resttemplate in my Android client (ive tried most methods as you can see):
HttpClient httpClient = new HttpClient();
Credentials defaultcreds = new UsernamePasswordCredentials(msisdn, password);
httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), defaultcreds);
httpClient.getParams().setSoTimeout(prefs.getServerTimeout());
httpClient.getParams().setConnectionManagerTimeout(3000);
httpClient.getParams().setContentCharset("utf-8");
httpClient.getParams().setCredentialCharset(prefs.getCredentialsEncoding());
httpClient.getParams().setHttpElementCharset("utf-8");
httpClient.getParams().setUriCharset("utf-8");
CommonsClientHttpRequestFactory requestFactory = new CommonsClientHttpRequestFactory(httpClient);
requestFactory.setReadTimeout(prefs.getServerTimeout());
RestTemplate restTemplate = new RestTemplate(requestFactory);
// Add message converters
List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
MappingJacksonHttpMessageConverter json = new MappingJacksonHttpMessageConverter();
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
json.setSupportedMediaTypes(supportedMediaTypes);
mc.add(json);
restTemplate.setMessageConverters(mc);
// Set our specific error handler
restTemplate.setErrorHandler(new MyErrorHandler());
this is my http response, copied from restclient in Firefox if i run the same request there:
Status Code: 401 Unauthorized
Content-Length: 954
Content-Type: text/html;charset=utf-8
Date: Sat, 19 Jan 2013 23:53:10 GMT
ERROR: För att <contents cut out but as you see Scandinavian char looks fine here >
Server: Apache-Coyote/1.1
WWW-Authenticate: Basic realm="rest"