java - Post Multipartfile to Rest Service using rest template -


i working spring 3 , resttemplate. have basically, 2 applications , 1 of them have post values other app. through rest template.

when values post strings, works perfectly, when have post mixed , complex params (like multipartfiles) converter exception.

as example, 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 other side... have web application (app2) receives parameters 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!... null");         } else {             system.out.println("yes!... work done!");         }         return "redirect:postupload";     } 

i following error

org.springframework.http.converter.httpmessagenotwritableexception: not write request: no suitable httpmessageconverter found request type [org.springframework.web.multipart.commons.commonsmultipartfile]     @ org.springframework.http.converter.formhttpmessageconverter.writepart(formhttpmessageconverter.java:292)     @ org.springframework.http.converter.formhttpmessageconverter.writeparts(formhttpmessageconverter.java:252)     @ org.springframework.http.converter.formhttpmessageconverter.writemultipart(formhttpmessageconverter.java:242)     @ org.springframework.http.converter.formhttpmessageconverter.write(formhttpmessageconverter.java:194)     @ org.springframework.http.converter.formhttpmessageconverter.write(formhttpmessageconverter.java:1)     @ org.springframework.web.client.resttemplate$httpentityrequestcallback.dowithrequest(resttemplate.java:588)     @ org.springframework.web.client.resttemplate.doexecute(resttemplate.java:436)     @ org.springframework.web.client.resttemplate.execute(resttemplate.java:415)     @ org.springframework.web.client.resttemplate.postforobject(resttemplate.java:294)     @ com.yoostar.admintool.web.uploadtestcontroller.create(uploadtestcontroller.java:86)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) 


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -