Uploaded image for project: 'Spring for Android'
  1. Spring for Android
  2. ANDROID-37

Issue with alternate character set and SimpleXmlMessageConverter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 1.0.0.M4
    • Component/s: None
    • Labels:
      None

      Description

      Non UTF-8 charsest response seems to not be working. Response is text/xml;charset=ISO-8859-1, but altering the mediatype does not resolve it.

      The error message is: org.springframework.web.client.RestClientException : Could not extract response: no suitable HttpMessageConverter found for response type [com.acme.Feed] and content type [text/xml;charset=ISO-8859-1]

      Code Example:

      HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

      RestTemplate restTemplate = new RestTemplate(requestFactory);

      List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
      messageConverters.add(new FormHttpMessageConverter());
      messageConverters.add(new StringHttpMessageConverter());

      SimpleXmlHttpMessageConverter xmlMessageConverter = new SimpleXmlHttpMessageConverter();
      ArrayList supportedMediaTypes = new ArrayList();

      MediaType mediaType = new MediaType("text", "xml", Charset.forName("ISO-8859-1"));
      supportedMediaTypes.add(mediaType);
      xmlMessageConverter.setSupportedMediaTypes(supportedMediaTypes);

      messageConverters.add(xmlMessageConverter);
      restTemplate.setMessageConverters(messageConverters);

      HttpHeaders headers = new HttpHeaders();

      ResponseEntity responseEntity =
      restTemplate.exchange(restURL,
      HttpMethod.GET,
      new HttpEntity<String>(headers),
      Class.forName(com.acme.Feed));

      XML Response:
      <feed>
      <feedname>Alerts</feedname>
      <authData>
      <token>...</token>
      <username>...</username>
      <employeeId>...</employeeId>
      </authData>
      <dataMessages>
      <dataMessage>
      ...
      </dataMessage>
      </dataMessages>
      </feed>

        Attachments

          Activity

            People

            • Assignee:
              rclarkson Roy Clarkson
              Reporter:
              rclarkson Roy Clarkson
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: