Reputation: 163
So, I'm a real java beginner.. I'm doing an application with lot of work and researching...
The thing is. I need to post some information with multipart/form-data... I used to do it with Json HashMap. But don't know which object to use instead... Here is my actioncontroller post:
HashMap<String, ContentDTO> cnt = new HashMap<String, ContentDTO>();
ContentDTO contentDTO = new ContentDTO();
contentDTO.setExternal_id("CNT1");
contentDTO.setTemplate_type_id(103);
contentDTO.setChannel_id("CHN1");
contentDTO.setTitle("Conteudo1");
contentDTO.setText("Conteudo teste 1");
RulesDTO rules = new RulesDTO();
SimpleDateFormat publish_date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss-SSS");
java.util.Date pdate = publish_date.parse("2012-12-28 11:18:00-030");
java.sql.Timestamp pubdate = new java.sql.Timestamp(pdate.getTime());
rules.setPublish_date(pubdate);
SimpleDateFormat expiration_date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss-SSS");
java.util.Date edate = expiration_date.parse("2013-12-28 11:18:00-030");
java.sql.Timestamp expdate = new java.sql.Timestamp(edate.getTime());
rules.setExpiration_date(expdate);
rules.setNotify_publish(true);
rules.setNotify_expiration(false);
rules.setHighlihted(true);
contentDTO.setRules(rules);
InteractionsDTO interactions = new InteractionsDTO();
interactions.setAllow_comment(true);
interactions.setAuto_download(false);
contentDTO.setInteractions(interactions);
cnt.put("content",contentDTO);
HttpEntity<HashMap<String, ContentDTO>> request = new HttpEntity<HashMap<String, ContentDTO>>(cnt, httpHeaders);
Can anyone helps me out??
Upvotes: 0
Views: 3015
Reputation: 697
As you are required to upload using multipart I think you must use a File object, specifically the MultipartFile from Spring.
Using Spring you must work in the UI layer using Spring Controllers, it's not necessary to manage the HttpEntity. Just declare the multipart resolver in your configuration file.
<beans>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
<!-- Declare explicitly, or use <context:annotation-config/> -->
<bean id="fileUploadController" class="examples.FileUploadController"/>
</beans>
This is extracted from official Spring 3 Documentation. You can check there some examples. Here I will give you some more: Spring 3 File Upload Example , Spring MVC file upload.
Finally I would suggest you using the MVC pattern. Don't create the DTO and use it's accessors inside the UI layer, create a Service or Facade in the business layer to do that.
Upvotes: 1