47
I am working with Spring 3 and RestTemplate. I have basically, two applications and one of them have to post values to the other app. through rest template.
When the values to post are Strings, it's work perfect, but when i have to post mixed and complex params (like MultipartFiles) i get an converter exception.
As example, i have this:
App1 - PostController:
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute UploadDTO pUploadDTO,
BindingResult pResult) throws URISyntaxException, IOException {
URI uri = new URI("http://localhost:8080/app2/file/receiver");
MultiValueMap<String, Object> mvm = new LinkedMultiValueMap<String, Object>();
mvm.add("param1", "TestParameter");
mvm.add("file", pUploadDTO.getFile()); // MultipartFile
Map result = restTemplate.postForObject(uri, mvm, Map.class);
return "redirect:postupload";
}
On the other side... i have another web application (App2) that receives the parameters from the App1.
App2 - ReceiverController
@RequestMapping(value = "/receiver", method = { RequestMethod.POST })
public String processUploadFile(
@RequestParam(value = "param1") String param1,
@RequestParam(value = "file") MultipartFile file) {
if (file == null) {
System.out.println("Shit!... is null");
} else {
System.out.println("Yes!... work done!");
}
return "redirect:postupload";
}
My application-context.xml:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean class="org.spri