Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet 3.1 - Multipart async processing

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! :)

like image 709
Francisco Carriedo Scher Avatar asked Sep 16 '13 14:09

Francisco Carriedo Scher


2 Answers

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.

like image 119
npgall Avatar answered Nov 15 '22 08:11

npgall


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).

like image 35
Jarym Avatar answered Nov 15 '22 08:11

Jarym