1

Here's my use case: I am implementing a finatra server, that should be able to receive many concurrent large requests. These requests have a large body (several megabytes) comprised of many small json objects, concatenated.

I'd like to avoid loading the entire request body into memory. I'm looking for a way to read the request body in chunks, and use a json parser that supports this sort of async parsing.

In node.js this can be achieved by using the jsonp package (see the example - https://github.com/jaredhanson/node-jsonsp/blob/master/examples/twitter-stream/app.js).

Can I do something similar with finatra (and how)?

PS - I also posted the question here, but got no answer so far.

Amir Tuval
  • 317
  • 1
  • 7

1 Answers1

0

This is not currently possible with Finatra. Finatra will not call your route until the entire request has been received and memorized into a ChannelBuffer. In addition, Finatra also reads the request as a single chunk so you cannot receive any body longer than ~2MB. Setting com.twitter.finatra.config.maxRequestSize to something higher than 2048 will cause it to crash at runtime.

I've switched to Play Framework using the NettyServer embed and "String Interpolating Routing DSL" to retain a DSL similar to Finatra.

Arne Claassen
  • 14,088
  • 5
  • 67
  • 106