Ok. I think now I understand the problem. We are trying to configure the wrong thing here. We don't care about the max length but instead in memory threshold size. I should have read the title of your question more carefully, my fault. Now coming back to your actually question. The default memory threshold is not configurable at this moment. As a workaround I think we can provide our own body parser that works completely in-memory by reusing the existing raw body parser. At this moment this is written in Scala but I am sure we can re-write this in Java as well.
//in memory raw body parser. Save it as InMemoryRawBodyParser.scala file in your play project
import play.api.mvc._
import play.mvc.Http.{ RequestBody }
import play.core.j.JavaParsers._
class InMemoryRawBodyParser extends play.mvc.BodyParser {
val inMemoryBufferSize = 10 * 1024 //this is what you need to configure for the buffer size
def parser(maxLength: Int): BodyParser[RequestBody] = {
parse.maxLength(maxLength, parse.raw(inMemoryBufferSize)).map { body =>
body
.left.map(_ => DefaultRequestBody(isMaxSizeExceeded = true))
.right.map { raw =>
DefaultRequestBody(raw = Some(raw))
}.fold(identity, identity)
}
}
}
And finally use it in your Java controller like following:
@BodyParser.Of(value = InMemoryRawBodyParser.class)
public static Result index() {
System.out.println(">>>>>> " + request().body().asRaw().size());
...
}
HTH
Nilanjan, Developer & Consultant
Typesafe Inc.