|
I have what I think is a silly question, but I haven't been able to solve it via the Grails documentation nor searching on the web.
I am implementing a REST server and am trying to build the POST operation. I have my UrlMappings as follows: "/person/$id?" (resource:"person") and my PersonController.save() method is being called, so all of that is good. But I need to get the raw POST data and I can't seem to do that. I'm not using the default XML/JSON converters but am instead using a JAXB annotated set of domain classes and EclipseLink's MOXy JAXB implementation. My save() code therefore needs to do the manual unmarshalling: def save() { JAXBContext context = JAXBContext.newInstance(Person.class) Unmarshaller unmarshaller = context.createUnmarshaller() Person personInstance = unmarshaller.unmarshal(????); if (!personInstance.save(flush: true)) { response.status = response.SC_BAD_REQUEST } else { render personInstance.id; } } My problem is figuring out what to put in the unmarshal call above. I've debugged this method and at that point, the request.reader is empty, and the params have been parsed like so: [<Person xmlns:"resource-namespace"><name>John Smith><dob>1970-11-27</dob></Person>, action:[GET:show, PUT:update, DELETE:delete, POST:save], controller:person] My posted XML was "<Person xmlns="resource-namespace"><name>John Smith><dob>1970-11-27</dob></Person>", so that is obviously being treated as a map entry and being broken in two. I've tried adding parseRequest:false to my UrlMappings but that doesn't seem to change anything. And in my debug browsing, there just didn't seem to be a request or controller attribute where I get the raw POSTed data. Help? Thanks,
|
It was. :)
After hitting send, I realized that I hadn't added "Content-type:text/xml" to my posting. As soon as I did that, the POST data wasn't being parsed and the request.reader had data. My bad. Nothing to see here. Oh look, a squirrel... On 2012-07-30, at 2:51 PM, Jean-Henri Duteau wrote:
|
| Powered by Nabble | Edit this page |
