Announcement Announcement Module
Collapse
No announcement yet.
outbound-channel-adapter : Delete files after copying to output directory . Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • outbound-channel-adapter : Delete files after copying to output directory .

    Hi , i am using spring-integration-2.1.0 . I am copying the file using integration.xml . The code is as follows .

    <bean id="fileInChannel" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location">
    <value>/WEB-INF/file.properties</value>
    </property>
    </bean>
    <bean id="fileHandler" class="com.kensho.dms.intg.FileCopyHandler" scope="singleton" />
    <file:inbound-channel-adapter id="inputSource" directory="file:${input.directory}" prevent-duplicates="false" channel="fileInputChannel" >
    <integrationoller id="filePoller" fixed-rate="10" />
    </file:inbound-channel-adapter>



    <integration:channel id="fileInputChannel" />


    <integration:chain input-channel="fileInputChannel" output-channel="fileProcessChannel" >
    <integration:service-activator ref="fileHandler" method="handleFile" />
    </integration:chain>

    <integration:channel id="fileProcessChannel" />

    <file:outbound-channel-adapter id="staging" directory="${output.directory}" delete-source-files="true" channel="fileProcessChannel" />

    </beans>



    after copying the file i am deleting the souce file using following code .

    <file:outbound-channel-adapter id="staging" directory="${output.directory}" delete-source-files="true" channel="fileProcessChannel" />


    Till here every things works great . Now i want to check , if any duplicate file arrives in output directory then rename it . Any solution is welcome .

  • #2
    Assuming fileHandler creates a message with a payload of java.io.File...

    1. Make fileProcessChannel a <publish-subscribe-channel/>
    2. Make the first subscriber (order="1") a

    Code:
    <service-activator ... "expression="new java.io.File(${output.directory}/payload.name).renameTo('someOtherName')" />
    3. Make the outbound channel adapter the second subscriber (order="2")

    The result of the rename (true or false) will be discarded by sending it to nullChannel.
    Last edited by Gary Russell; Sep 13th, 2012, 08:11 AM.

    Comment


    • #3
      My expression was wrong; I changed it to...

      Code:
      expression="new java.io.File(${output.directory}/payload.name).renameTo('someOtherName')
      But you might want to use a java class rather than an expression if you want more sophistication in the rename.

      Comment

      Working...
      X