Reputation: 1
Before using play framework , I can use codes below to get the raw post data,
ServletInputStream inputStream = request.getInputStream();
if(inputStream!=null){
String xml = StreamUtils.copyToString(inputStream,Charset.forName("utf-8"));
System.out.println("xml: "+xml);
EventMessage eventMessage = XMLConverUtil.convertToObject(EventMessage.class,xml);
......
return;
}
when using play framework ,the play.mvc.Http.Request seems has no method to get the inputstream, is there any method to get the ServletInputStream in play?
Upvotes: 0
Views: 945
Reputation: 2404
In your Play controller, you can access the request, from there you can get the body of the request which will contain the String you are looking for:
public static Result index() {
String xml = request().body().asText();
...
return ok("ok);
}
Note: you can also use the method asXml()
of your body.
For more information: http://www.playframework.com/documentation/2.3.x/JavaBodyParsers
Upvotes: 1