How to fix breaking changes in camel-rest with version 3.16.0

327 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

I found the solution.

In order for the stream to stay open you have to tell camel to not use stream caching:

getCamelContext().setStreamCaching(false);

When using spring Boot the alternative is setting it via the config:

camel:
  springboot:
    stream-caching-enabled: false

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