In camel version 3.16.0 embedded routes were removed from the rest definition: https://issues.apache.org/jira/browse/CAMEL-17675
This introduces this problem:
Parsing Multipart as a Stream
We expose a rest endpoint where a user can upload a multipart/form-data
request which has metadata and files alike.
Until now we used apache to parse the request and save the file parts into a temporary folder:
Message message = exchange.getMessage();
HttpServletRequest request = message.getBody(HttpServletRequest.class);
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List<FileItem> items = servletFileUpload.parseRequest(request);
// Iterate over items, save files, parse meta-data etc.
This now throws an exception because the InputStream of the Request is closed.
Using a different way of parsing the multipart request is unfortunatelly not really an option because we potentially receive very big files, that we just have to read via a Stream. The fact that its closed means all the content has been read and all that file data is in the ram which will not go well.
I found the solution.
In order for the stream to stay open you have to tell camel to not use stream caching:
When using spring Boot the alternative is setting it via the config:
Both will disable stream caching globally. I have not found a way to diable it for just one rest endpoint, but it will do the trick