I'm struggling to work out how best to handle a multipart/form-data
using the REST DSL.
My first attempt was to use Camel's MIME-Multipart data handler [1]
which works, but gave me the problem that it automatically keeps the
first part of the message (first form field) as the Exchange body, but
does not copy the Content-Disposition header of the part to the headers
for the message.
Without the Content-Disposition header I can't tell which form field
this corresponds to, and the client(s) that send the request do not
provide the form fields in the same order. Short story - if I could
guarantee which is the first part then I'd be OK, but I can't.
My next attempt was to use the commons-fileupload package [2] which
works with the raw HttpServletRequest. But this didn't work as I got an
IOException with a 'Stream closed' message when trying to read. Seems
that Camel is somehow getting to the request first?
My third attempt was to use the Servlet API and call
HttpServletRequst.getParts() method [3] to get the parts, but this
failed with an IllegalStateException with this message: "Unable to
process parts as no multi-part configuration has been provided".
Googling [4] tells me that I need to annotate the servlet with the
@MultipartConfig annotation, but of course using Camel's REST DSL I
don't have access to the servlet class.
Any suggestions for how to handle this. To summarise the needs:
1. need to handle the form fields in any order
2. some of the parts can be large in size so I need an approach that
streams the data or does not keep it in memory.
[1] http://camel.apache.org/mime-multipart.html
[2] https://commons.apache.org/proper/commons-fileupload/
[3]
https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html#getParts--
[4]
https://www.moreofless.co.uk/unable-process-parts-no-multi-part-configuration-provided/