0

In spring boot - integration, have a filter which will rename the file , if the instance successfully rename the file only,it should continue the flow else it will be passed to null channel.

Would like to log the null channel to see the file name which is not successfully renamed.

Tried below solution.But exception occurs during application startup. can you suggest on the solution to achieve this.

<integration:filter input-channel="filesInChannel" expression="headers['file_originalFile'].renameTo(new java.io.File(headers['file_originalFile'].absolutePath + '.lock'))" 
        output-channel="filesHeaderEnricher" discard-channel="nullChannel" throw-exception-on-rejection="false">
</integration:filter> 
<integration:channel id="nullChannel">
  <integration:interceptors>
    <integration:wire-tap channel="logNullChannel"/>
 </integration:interceptors>
</integration:channel>
<integration:logging-channel-adapter id="logNullChannel" level="DEBUG"/>

Exception if logging-channel-adapter added for nullchannel:

  java.lang.IllegalStateException: The bean name 'nullChannel' is reserved.
    at org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor.registerNullChannel(DefaultConfiguringBeanFactoryPostProcessor.java:112) ~[spring-integration-core-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
    at org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor.postProcessBeanFactory(DefaultConfiguringBeanFactoryPostProcessor.java:63) ~[spring-integration-core-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
    at 
Jessie
  • 963
  • 5
  • 16
  • 26

1 Answers1

1

The nullChannel can’t be intercepted at all. You need to consider some other channel for your use-case or turn on debug logging for the NullChannel category:

 if (this.loggingEnabled && this.logger.isDebugEnabled()) {
        this.logger.debug("message sent to null channel: " + message);
    }
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118