Ankur
Ankur

Reputation: 437

Playframework Java - How to receive chunked HTTP request in controller

I have a play controller in java. The request is of 15MB in size. This request is coming from APIGEE in a streamed manner. I have used raw body parser in the controller to write the data into the file. But I think it writes the whole request data into a file at once. Which means the whole request must be in memory at one point to a time before it gets written to a file. Is there any way to receive stream request in play framework (JAVA)?

Upvotes: 0

Views: 1654

Answers (1)

James Roper
James Roper

Reputation: 12850

The raw body parser does not buffer the whole body into memory, it buffers the body up to a point (configured using play.http.parser.maxMemoryBuffer, defaults to 100kb), and once that is exceeded, it flushes the body to a file and starts writing it to the file, but it also has a limit on how much data it will write to a file, which is configured using play.http.parser.maxDiskBuffer, and this defaults to 10mb. Your 15mb body is probably exceeding that limit, so you need to increase play.http.parser.maxDiskBuffer accordingly. This is all explained in the documentation.

To answer your actual question on how to stream requests, documentation for writing custom body parsers in Java is here:

https://www.playframework.com/documentation/2.6.x/JavaBodyParsers#Writing-a-custom-body-parser

That explains most things you need to know about how Play body parsers work and therefore how to do streaming body parsing, no point in duplicating that documentation in this answer.

Upvotes: 2

Related Questions