I’ve searched around for docs/examples of processing a POST request with XML as the body but can’t seem to find up-to-date examples for play 1.2.4 (there is a nice annotation you can use for play 2.0 though).
I have a Flex app that is posting XML like so:
public function post( url:String, xml:XML ):void
{
var service:HTTPService = new HTTPService();
var responder:Responder = new Responder( postResult, postFault );
var token:AsyncToken;
service.method = "POST";
service.contentType = "application/xml";
service.resultFormat = "e4x";
service.url = url;
token = service.send( xml );
token.addResponder( responder );
}
How can I access the body as XML so I can process it with JAXB?
thanks!
There are two methods that I know of.
You can use
request.body, which returns an InputStream. Probably a little long-winded for people used to simplicity of Play.Simply call
params.get("body"). This will return the whole of the body.Clearly you are most likely to want to go with option 2, but for some use cases option 1 may be preferred.