
Originally Posted by
MikeOliverAZ
I can now fetch data from the application in XML or JSON with another application, but I cannot find documentation or articles or tutorial on how to leverage the same entities and do RESTful POST and PUT to put data into the application in XML or JSON.
I found the following http://www.ibm.com/developerworks/we...erv/index.html to be quite good.
But in comparing sources I am closer but still not quite there yet.
For example in the above it shows the controller with @RequestMapping for POST to be
Code:
@RequestMapping(method=RequestMethod.POST, value="/employee")
public ModelAndView addEmployee(@RequestBody String body) {
Source source = new StreamSource(new StringReader(body));
Employee e = (Employee) jaxb2Mashaller.unmarshal(source);
employeeDS.add(e);
return new ModelAndView(XML_VIEW_NAME, "object", e);
}
Where my Roo controller aspect @RequestMapping for POST to be
Code:
@RequestMapping(method = RequestMethod.POST)
public String HZoneController.create(@Valid HZone HZone, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("HZone", HZone);
return "hzones/create";
}
uiModel.asMap().clear();
HZone.persist();
return "redirect:/hzones/" + encodeUrlPathSegment(HZone.getId().toString(), httpServletRequest);
}
Given the warning on the Roo_Controller.aj
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
I am wondering the best course of action to implement such that the Roo JSP views, form posts, etc. are retained, while adding REST XML AND REST JSON, POST AND PUT.
It seems to me the easiest to just have different @RequestMappings for different URI paths where one would be the current mapping is unchanged and new mappngs made for XML = /hzones/xml/ and JSON = /hzones/json/
Or is it better to create three controllers and leave the Roo Controller untouched?