org.springframework.messaging.MessageHandlingException: failed to write Message payload to file; nested exception is java.io.FileNotFoundException: target/output/dir/test2.writing (No such file or directory)

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • This is either a feature/improvement *OR* a bug-report. This depends on which route we want to go. I have been working on the *spring-integration-zip* extension. When unzipping files, I may end up with files in sub-directories. A subsequent splitter, will generate individual messages for each file entry. Payloads may be of type *byte[]* and using a *file-outbound-channel-adapter*, it would be nice to recreate the nested file+directory structure. While you can use the *directory-expression*, it would have been nice, for simplicity reasons, to specify the directory as part of *FileHeaders.FILENAME*. E.g.: ...setHeader(FileHeaders.FILENAME, "dir/test2") However, this leads to a cryptic error message: {code} Exception in thread "main" org.springframework.messaging.MessageHandlingException: failed to write Message payload to file; nested exception is java.io.FileNotFoundException: target/output/dir/test2.writing (No such file or directory) at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:309) at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99) at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101) at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97) at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:277) at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:239) at com.hillert.filetest.Main.main(Main.java:54) Caused by: java.io.FileNotFoundException: target/output/dir/test2.writing (No such file or directory) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:213) at org.springframework.integration.file.FileWritingMessageHandler.handleByteArrayMessage(FileWritingMessageHandler.java:379) at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:296) ... 9 more {code} A quick sample project is at: https://github.com/ghillert/si-file-test This raises ultimately the question: 1) Should FileHeaders.FILENAME be "directory-aware"? (only relative to base-output-directory) 2) Should we add something like FileHeaders.DIRECTORY? 3) State that we only support *directory-expression*? Even, if 3) is all we support. We should improve the error message, as it is cryptic. When using FileHeaders.FILENAME we should validate the value and ensure it does not contain path information. This may also somewhat relate to an old open Jira: INT-832 The official behavior should also be documented in the reference guide.
    via by Gunnar Hillert,
  • This is either a feature/improvement *OR* a bug-report. This depends on which route we want to go. I have been working on the *spring-integration-zip* extension. When unzipping files, I may end up with files in sub-directories. A subsequent splitter, will generate individual messages for each file entry. Payloads may be of type *byte[]* and using a *file-outbound-channel-adapter*, it would be nice to recreate the nested file+directory structure. While you can use the *directory-expression*, it would have been nice, for simplicity reasons, to specify the directory as part of *FileHeaders.FILENAME*. E.g.: ...setHeader(FileHeaders.FILENAME, "dir/test2") However, this leads to a cryptic error message: {code} Exception in thread "main" org.springframework.messaging.MessageHandlingException: failed to write Message payload to file; nested exception is java.io.FileNotFoundException: target/output/dir/test2.writing (No such file or directory) at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:309) at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99) at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101) at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97) at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:277) at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:239) at com.hillert.filetest.Main.main(Main.java:54) Caused by: java.io.FileNotFoundException: target/output/dir/test2.writing (No such file or directory) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:213) at org.springframework.integration.file.FileWritingMessageHandler.handleByteArrayMessage(FileWritingMessageHandler.java:379) at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:296) ... 9 more {code} A quick sample project is at: https://github.com/ghillert/si-file-test This raises ultimately the question: 1) Should FileHeaders.FILENAME be "directory-aware"? (only relative to base-output-directory) 2) Should we add something like FileHeaders.DIRECTORY? 3) State that we only support *directory-expression*? Even, if 3) is all we support. We should improve the error message, as it is cryptic. When using FileHeaders.FILENAME we should validate the value and ensure it does not contain path information. This may also somewhat relate to an old open Jira: INT-832 The official behavior should also be documented in the reference guide.
    via by Gunnar Hillert,
  • GitHub comment 1942#255760993
    via GitHub by Panciz
    ,
  • visual-studio-2012: mai 2015
    via by Unknown author,
  • Java En Francais: mai 2015
    via by Unknown author,
  • Petit problème quand je met un mod
    via by Unknown author,
    • org.springframework.messaging.MessageHandlingException: failed to write Message payload to file; nested exception is java.io.FileNotFoundException: target/output/dir/test2.writing (No such file or directory) at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:309) at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99) at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101) at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97) at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:277) at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:239) at com.hillert.filetest.Main.main(Main.java:54) Caused by: java.io.FileNotFoundException: target/output/dir/test2.writing (No such file or directory) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:213) at org.springframework.integration.file.FileWritingMessageHandler.handleByteArrayMessage(FileWritingMessageHandler.java:379) at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:296) ... 9 more

    Users with the same issue

    Matty
    Matty1 times, last one,
    Unknown visitor1 times, last one,
    Axelo
    Axelo2 times, last one,
    rp
    rp1 times, last one,
    Eric Henderson
    Eric Henderson20 times, last one,
    149 more bugmates