Spring for Android
  1. Spring for Android
  2. ANDROID-37

Issue with alternate character set and SimpleXmlMessageConverter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major 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>

        Activity

        Hide
        Roy Clarkson added a comment -

        We should consider removing the check for the @Root annotation in the canRead() method. Simple requires this for writing, but does not for reading.

        Show
        Roy Clarkson added a comment - We should consider removing the check for the @Root annotation in the canRead() method. Simple requires this for writing, but does not for reading.
        Hide
        Roy Clarkson added a comment -

        We are not supporting alternate character sets in the read and write methods. The inputMessage and outputMessage parameters should be checked for an alternate character set, which should be used to create the InputStreamReader and OutputStreamWriter that are passed to the Simple Serializer.

        Show
        Roy Clarkson added a comment - We are not supporting alternate character sets in the read and write methods. The inputMessage and outputMessage parameters should be checked for an alternate character set, which should be used to create the InputStreamReader and OutputStreamWriter that are passed to the Simple Serializer.
        Hide
        Roy Clarkson added a comment -

        Changes for better encoding support when reading and writing with Simple. Removed check for @Root annotation when reading an XML source.

        Show
        Roy Clarkson added a comment - Changes for better encoding support when reading and writing with Simple. Removed check for @Root annotation when reading an XML source.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: