Announcement Announcement Module
Collapse
No announcement yet.
RESTTemplate error: Could not write request: no suitable HttpMessageConverter found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RESTTemplate error: Could not write request: no suitable HttpMessageConverter found

    I am using the following code to upload a file to a service on the server side using springresttemplate:
    @RequestMapping(value = "/services/list/scan", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    public void scanListUpload(
    HttpServletResponse request,
    @RequestParam MultipartFile uploadFile,
    HttpServletResponse response) throws IOException {
    LOGGER.debug("ENTERED scanListUpload()");
    MultiValueMap<String, Object> mapData = new LinkedMultiValueMap<String, Object>();
    mapData.add("file", uploadFile);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "multipart/form-data"); // we are sending a form
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
    restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
    restTemplate.getMessageConverters().add(new ResourceHttpMessageConverter());

    String result = null;
    try{
    result = restTemplate.exchange(
    "http://gis03691.devcloud.ge.com:8008/metascan_rest/scanner?method=scan",
    HttpMethod.POST,
    new HttpEntity<MultiValueMap<String, Object>>(mapData, headers),
    String.class
    ).getBody();
    }
    catch(Exception e){
    LOGGER.debug("exception is: " + e.getMessage());
    }
    LOGGER.debug("status code for metascan" + result);



    }
    I am getting an exception when executing the above code -Could not write request: no suitable HttpMessageConverter found for request type [org.springframework.web.multipart.commons.CommonsM ultipartFile]

    The spring version is: 3.1.0.RELEASE
    Could someone help how to resolve this error?
Working...
X