I'm working on a project where Spring Integration is used as a proxy to distribute HTTP requests to the relevant services and send back the answers to the client. Incoming HTTP requests are first preprocessed and sent to an HTTP outbound gateway. On its way back to the client, the HTTP response is first written to a file, using a file outbound gateway:
<!-- write the message payload to ./toto/ and forward it to the http channel -->
<int-file:outbound-gateway request-channel="outputFileChannel"
reply-channel="outputHttpChannel"
directory="./toto/"
filename-generator-expression="headers.file_name + '.json'"
mode="REPLACE"/>
<!-- process the message before returning it to the inbound reply channel -->
<int:chain input-channel="routingOutputHttpChannel"
output-channel="inboundReplyChannel">
...
</int:chain>
The documentation for the file outbound gateway says that "after writing the file, it also sends it to the reply channel as the payload of a message". My understanding was that the file contents was sent as the message payload, but from what I've implemented, it is the name of the file written that is sent as payload. The filename is irrelevant to me at this point. Is there a way to directly send the file contents? If not, what should I do the read the contents of the file that was written? Plug a file inbound channel adapter (seems a bit redundant)?
Moreover, what's the proper way to handle the file not being written (so as to forge a specific HTTP response)? My guess would be catching a MessageDeliveryException...