How to access XML object in Restlet 2.0 thats wrapped inside a Representation object?
-
19-09-2019 - |
Question
Hi I am developing an application with Flex for the GUI and Restlet for the webservices. I have a strange problem. I put my XML as a property on a generic object, and send it as part of a POST request. But in the Restlet webservice, this XML is irretrievable. How do I retrieve it? I tried initialising the received Representation object to a DomRepresentation, but thats not working. If I put the received Representation object into a Form object, then getFirstValue is returning that XML as a string!
I noticed that the contentType of the HTTPService was application/www-form-encoded so I set it to application/xml and its not helping either.
I use restlet 2.0m6 and here is the code snippet that I use -
@Post
public Representation process(Representation entity)
{
try
{
DomRepresentation dom = new DomRepresentation(entity);
Document d = dom.getDocument();
.
.
} catch(Exception e)
{ e.printStackTrace(); }
and it throws a Null Pointer exception at the dom.getDocument() line. Which means no data actually arrived.
And my flex bit looks like this -
var service : HTTPService = new HTTPService();
service.method="POST";
service.contentType="application/xml"
service.url=url;
var token :AsyncToken = service.send(params);
where params is an XML object.
Solution