Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-integration : how to delete a file?

I'm working on a simple spring-integration project that selects some files (using file:inbound-channel-adapter) and based on those files imports some data into DB.

At the end it would like to have those files deleted as I no longer need them and so far I haven't figured out how to do that without coding.

file:outbound-channel-adapter is no go as it moves files instead of deleting them.

I'm trying to solve it with

<int:outbound-channel-adapter expression="headers['file_originalFile'].delete()" ... 

But I'm getting

Failed to convert value of type 'java.lang.String' to required type 'java.lang.Void';

Do you have any ideas how to solve it without coding?

like image 919
Maciej Avatar asked Jan 27 '26 14:01

Maciej


1 Answers

File.delete() returns a boolean and, by contract, an outbound channel adapter MUST return void (no output).

You can use a <service-activator/> with output-channel="nullChannel" to discard the result.

Or, you can use an expression evaluating advice on your ultimate consumer, as shown in the retry-and-more sample.

like image 53
Gary Russell Avatar answered Jan 30 '26 04:01

Gary Russell