CAMEL-24593: platform-http-starter - delete multipart uploads when the exchange is done - #1934
Open
Croway wants to merge 1 commit into
Open
CAMEL-24593: platform-http-starter - delete multipart uploads when the exchange is done#1934Croway wants to merge 1 commit into
Croway wants to merge 1 commit into
Conversation
oscerd
approved these changes
Sep 2, 2026
Croway
force-pushed
the
CAMEL-24593-platform-http-upload-cleanup
branch
from
September 2, 2026 13:12
fb9236f to
65edcc8
Compare
Contributor
Author
|
The CI failure here is Claude Code on behalf of Federico Mariani |
…e exchange is done
SpringBootPlatformHttpBinding.populateAttachments() copies every accepted
multipart upload into the servlet temp directory and uses that copy as the
attachment DataSource and, for a single upload, as the Path message body and
the CamelFilePath header. MultipartFile.transferTo() moves the container's part
file, so the container's own end-of-request cleanup no longer finds it, and
nothing in the starter deleted the copy either: every upload the application
accepted stayed on disk for the life of the process.
The copy was introduced in CAMEL-21461 so the body can be a Path and the
attachment stays readable after the servlet request completed, which is a good
reason to own the file - but owning it means removing it. The other HTTP
bindings do not leak: camel-http-common reads the part through the container
managed file, which the container deletes, and camel-platform-http-vertx has
deleteUploadedFilesOnEnd defaulting to true.
The binding now collects the temp files it created for a request and registers
a Synchronization through ExchangeExtension.addOnCompletion that deletes them
when the exchange is done being routed. The DataSource and the Path body point
at the files until then, so they cannot be deleted any earlier; the consumer
writes the HTTP response before doneUoW, so the response is already out.
The opt-out mirrors the Vert.x option. Endpoint options are defined in upstream
camel-platform-http and cannot be extended from here, so the option is a new
starter owned configuration class, SpringBootPlatformHttpServerProperties,
next to the existing camel.component.platform-http.server.undertow.accesslog
properties:
camel.component.platform-http.server.delete-uploaded-files-on-end=false
It is wired from the auto configuration through the engine and the consumer
onto the binding, and defaults to true. Existing public constructors are
unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Croway
force-pushed
the
CAMEL-24593-platform-http-upload-cleanup
branch
from
September 2, 2026 16:56
65edcc8 to
4cfb23e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes https://issues.apache.org/jira/browse/CAMEL-24593
What
SpringBootPlatformHttpBinding.populateAttachments()copies every accepted multipart upload into the servlettemp directory (
ServletContext.TEMPDIR) under a random UUID name, and uses that copy as the attachmentDataSourceand, for a single upload, as thePathmessage body and theCamelFilePathheader.MultipartFile.transferTo()moves the container's part file, so the container's own end-of-request cleanup nolonger finds anything to delete, and nothing in the starter deleted the copy either. Every upload the
application accepted stayed on disk for the life of the process, including uploads a route only inspected and
discarded.
The copy itself is deliberate - it was introduced in CAMEL-21461 so the body can be a
Pathand the attachmentstays readable after the servlet request completed - but owning the file means removing it.
The other HTTP bindings do not leak:
camel-http-common'sDefaultHttpBindingreads the part through thecontainer managed file, which the container deletes at the end of the request, and
camel-platform-http-vertxhas
deleteUploadedFilesOnEnd, defaulting totrue.How
a
SynchronizationAdapterthroughexchange.getExchangeExtension().addOnCompletion(...)that deletes themwhen the exchange is done being routed. The attachment
DataSourceand thePathbody point at the filesuntil then, so they cannot be deleted any earlier; the consumer writes the HTTP response before
doneUoW, sothe response is already out when the deletion happens.
camel.component.platform-http.server.delete-uploaded-files-on-end, defaulttrue. The endpoint optionslive in upstream
camel-platform-httpand cannot be extended from this repository, so the option is a newstarter owned
@ConfigurationPropertiesclass,SpringBootPlatformHttpServerProperties, alongside theexisting
camel.component.platform-http.server.undertow.accesslog.*. It is wired throughSpringBootPlatformHttpAutoConfiguration->SpringBootPlatformHttpEngine->SpringBootPlatformHttpConsumeronto the binding. Existing public constructors are unchanged; the engine gained an extra constructor that
defaults to
true.Behaviour change and how to opt out
Uploaded temp files are now removed after the exchange completes. Routes that consume the upload while routing
(file producer, streaming it out, unmarshalling it) are unaffected - routing a
Pathbody to a file producercopies the content. A route that stores the temp path and reads the file after the exchange has finished must
set:
camel.component.platform-http.server.delete-uploaded-files-on-end=falseand is then responsible for deleting the file itself. An upgrade guide entry has been drafted for the
apache/camel4.23 upgrade guide and will be submitted separately.Tests
SpringBootPlatformHttpUploadCleanupTest- single upload deleted after the exchange is done (also assertingthe route saw the file, and that
CamelFilePathand thePathbody pointed at it), multi attachment uploadwhere both copies are deleted, and a multipart request without a file part.
SpringBootPlatformHttpUploadCleanupDisabledTest- with the opt-out the file is still there after theresponse.
Thread.sleep.camel-platform-http-startersurefire suite run locally, green (rebased on currentmain).Docs:
src/main/docs/platform-http.adocgained a "File uploads" section; the generatedsrc/main/docs/platform-http.jsonanddocs/spring-boot/modules/ROOT/pages/starters/platform-http.adocwereregenerated by the module build.
Claude Code (Opus 5) on behalf of Federico Mariani