Announcement Announcement Module
No announcement yet.
no suitable HttpMessageConverter found Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • no suitable HttpMessageConverter found

    I get the following error when trying to upload a file using the following code. Any help understanding what's missing would be appreciated. I'm more or less following the example at, but using RoboSpice instead of AsyncTask
    An exception occured during request network execution :Could not write request: no suitable HttpMessageConverter found for request type [org.springframework.util.LinkedMultiValueMap] and content type [multipart/form-data]
    class UploadJsonRequest extends SpringAndroidSpiceRequest<APIResponseUpload> {

    private MultiValueMap<String, Object> formData;

    public UploadJsonRequest() {
    super( APIResponseUpload.class );

    public APIResponseUpload loadDataFromNetwork() throws Exception {

    HttpHeaders requestHeaders = new HttpHeaders();

    // Sending multipart/form-data
    requestHeaders.setContentType(MediaType.MULTIPART_ FORM_DATA);

    Resource resource = new ClassPathResource("res/drawable/logo.png");

    // populate the data to post
    formData = new LinkedMultiValueMap<String, Object>();
    formData.add("description", "Spring logo");
    formData.add("file", resource);

    // Populate the MultiValueMap being serialized and headers in an HttpEntity object to use for the request
    HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(
    formData, requestHeaders);

    //ResponseEntity<String> response =, HttpMethod.POST, requestEntity, String.class);

    return getRestTemplate().postForObject(URI, requestEntity, APIResponseUpload.class);
    return new UploadJsonRequest();

  • #2
    What I needed to do was

    HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(
    parts, requestHeaders);

    RestTemplate restTemplate = getRestTemplate();
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

    return restTemplate.postForObject(URI, requestEntity, APIResponseUpload.class);

    What I don't understand is why... Other examples I've followed don't need this, and the message converters specifically are claimed to be included in Android 2.1 +. I'm building for ICS, so this shouldn't have been necessary. Anybody can shed some light on this?


    • #3
      As you noted, the default RestTemplate constructor does not include any message converters. This decision was made to reduce the number of objects being instantiated, due to Android's more limited resources (especially on older devices). Unfortunately, this has caused some confusion in the community and we are considering reverting to a default constructor in a future release that is more consistent with Spring Framework's RestTemplate.


      • #4
        OK, that makes sense. I think the most important thing would be for this to be VERY clearly documented. It took me many hours to figure the correct settings out, being new to Android Spring, because all the documentation I could find specifically claimed that what I needed to do was not necessary. Hopefully this thread helps some other folks out.


        • #5
          Understood, and we certainly appreciate the feedback. It is documented in the reference manual, and in the javadoc. But that doesn't mean anything if people are still struggling with this. You aren't the only person to identify this issue, so it's clear we need to maintain that consistency with Spring Framework as much as possible. Thanks again.