gnodet opened a new pull request, #25360:
URL: https://github.com/apache/camel/pull/25360
## Summary
Allow the stream caching spool directory to be resolved per-Exchange, so
custom `StreamCachingStrategy` implementations can direct each route's spooled
bytes to a separate directory.
**Problem:** The spool directory is resolved once at startup in
`DefaultStreamCachingStrategy.doStart()` and stored as a single context-wide
`File`. The `Exchange` is available in `CachedOutputStream`'s constructor but
is dropped before the spool directory is selected in
`TempFileManager.createOutputStream()`. This makes it impossible for custom
strategies to make per-route decisions.
**Fix (3 source files, 1 test file):**
- **`StreamCachingStrategy`** (camel-api): Add `default File
resolveSpoolDirectory(Exchange exchange)` method that falls back to
`getSpoolDirectory()`. Full backward compatibility — existing custom
implementations compile and work unchanged.
- **`CachedOutputStream`** (camel-support): Store the `Exchange` as a field
and pass it through `pageToFileStream()` to
`TempFileManager.createOutputStream()`.
- **`FileInputStreamCache.TempFileManager`** (camel-support): Call
`strategy.resolveSpoolDirectory(exchange)` instead of
`strategy.getSpoolDirectory()`. Create the resolved directory on-demand if it
doesn't exist.
**Usage example:**
```java
DefaultStreamCachingStrategy strategy = new DefaultStreamCachingStrategy() {
@Override
public File resolveSpoolDirectory(Exchange exchange) {
String routeId = exchange.getFromRouteId();
if (routeId != null) {
return new File(getSpoolDirectory(), routeId);
}
return getSpoolDirectory();
}
};
```
## Test plan
- [x] `testDefaultResolveSpoolDirectoryReturnsSameDirectory` — default
behavior unchanged
- [x] `testPerExchangeSpoolDirectoryResolution` — custom strategy routes to
per-route subdirectory
- [x] `testPerExchangeSpoolDirWithDifferentRoutes` — two routes spool to
different subdirectories
- [x] `testPerExchangeSpoolDirFallsBackWhenNoRouteId` — falls back to base
directory when no route ID
- [x] All existing `CachedOutputStreamTest` tests pass (8/8)
- [x] All existing `StreamCaching*Test` tests pass (18/18)
🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of
@gnodet
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]