I am looking for a way to print the response body in the Play platform, I have this code:
object AccessLoggingAction extends ActionBuilder[Request] { def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = { Logger.info(s"""Request: id=${request.id} method=${request.method} uri=${request.uri} remote-address=${request.remoteAddress} body=${request.body} """) val ret = block(request) /* ret.map {result => Logger.info(s"""Response: id=${request.id} body=${result.body} """) } */ //TODO: find out how to print result.body (be careful not to consume the enumerator) ret } }
Currently, the code with comments does not work the way I wanted, I mean, it will print:
Response: id=1 body=play.api.libs.iteratee.Enumerator$$anon$18@39e6c1a2
So, I need to find a way to get a string from Enumerator [Array [Byte]]. I tried to understand the concept of Enumerator by reading this: http://mandubian.com/2012/08/27/understanding-play2-iteratees-for-normal-humans/
So ... if I understand correctly:
I should not clean out the counter in the process of converting it to String. Otherwise, the client will not receive anything.
Suppose I figure out how to implement the T / filter mechanism. But then ... would it not surpass the goal of the Play platform as a non-blocking streaming infrastructure (because I would build up a full array of bytes in memory before calling toString on it and finally registering it)?
So what is the right way to register a response?
Thanks in advance, Raka
source share