Russian characters converted to question mark in the REST response.

Solution Verified - Updated -

Issue

  • We are using RestTemplate of Spring framework and method 'getMessageConverters()' to convert the characters to UTF-8 encoding. But still it gives us ?????? instead of string. This same code we tested in our local environment without using fuse and its working fine.
  • The code is given below and attaching the same complete file.
RestTemplate restTemplate=getRestTemplate();
        restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName(Constants.CHAR_ENCODING)));
        StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
        stringHttpMessageConverter.setWriteAcceptCharset(true);
        for(int i=0;i<restTemplate.getMessageConverters().size();i++) {
            if(restTemplate.getMessageConverters().get(i) instanceof StringHttpMessageConverter) {
                restTemplate.getMessageConverters().remove(i);
                LOGGER.info("Adding new Encoding pattern.");
                restTemplate.getMessageConverters().add(i, stringHttpMessageConverter);
                break;
            }
            if(restTemplate.getMessageConverters().get(i) instanceof MappingJackson2HttpMessageConverter){
                try{
                ((MappingJackson2HttpMessageConverter) restTemplate.getMessageConverters().get(i)).setSupportedMediaTypes(mediaTypeList);
                }catch(Exception e){
                e.printStackTrace();
                }
            }
        }
// Calling service
response = restTemplate.exchange(constructDocumentUrl(url,umr,null,null),GET, getEntity(xchId), String.class);
//Response expecting in response.getBody()

Environment

  • Red Hat Fuse
    • 6.3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In