I am testing Servlet 3.1 API to process multipart requests. I am interested in processing some of the parts synchronously (text fields) and other asyncronously (file fields). At first sight it seems that it is not available in Servlet 3.1 (either totally async through request.getInputStream() in an async context or multipart processing similar to apache-commons-fileupload library).
Is there a way to get this sync/async processing using Servlet 3.1?
Thanks in advance for your time! :)
Synchronoss Technologies recently open sourced a non-blocking HTTP multipart parser which can be used with Servlet 3.1 here.
You just write your Servlet 3.1 ReadListener
, to pass incoming bytes to the NioMultipartParser
. The parser will make callbacks to your code for each of the parts received.
Disclaimer: I work for Synchronoss Technologies. We open sourced this because it was quite a headache to implement! There seems to be a gap in functionality provided by Servlet 3.1, so hopefully others will find this library useful.
I've been searching for a similar example and I'm surprised that after a year since the original question was posted there aren't many.
Anyway, I was about to write my own but my higher judgment kicked in and Google came to the rescue. The Grizzly project have written an asynchronous multi-part example here: https://grizzly.java.net/httpserverframeworkextras.html
This can't be plugged straight into a Servlet 3.1 readListener but I think it should be fairly straight forward to adapt it (my next task).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With