Search code examples
springspring-integrationsplitter

Spring Integration - Move File After Xpath-splitter


i'm working with spring integration and i have the next case: i'm reading a XML file with an int-file:inbound-channel-adapter and i split the file with a int-xml:xpath-splitter, the thing is that i need to move the file after been splitted.

I want all features of int-xml:xpath-splitter plus moving the file, should i implement a custom splitter extending XPathMessageSplitter? or is there any other way to do that with an out-of-box components?

Thanks.

<int-xml:xpath-splitter id="salesTransSplitter" 
                   input-channel="salesInputChannel"
                   output-channel="splitterOutChannel" order="1">
    <int-xml:xpath-expression expression="/sales_transactions/trans"/>      
</int-xml:xpath-splitter>   

Solution

  • Something like this should work...

    <int-file:inbound ... channel="foo" />
    
    <int:publish-subscribe-channel id="foo" />
    
    <int-xml:xpath-splitter input-channel="foo" ... order="1" />
    
    <int-service-activator input-channel="foo" order="2"
          expression="payload.renameTo(new java.io.File('/newDir/' + payload.name)" output-channel="nullChannel" />
    

    If you want to test the rename was successful, send to some other channel other than nullChannel - boolean true means success.

    EDIT

    Sorry about that; order should be supported on every consuming endpoint, I will open a JIRA issue.

    The order is not strictly necessary; if no order is present, the order they appear in the configuration will be used; I just prefer to make it explicit.

    There are (at least) two work arounds:

    1. Remvoe the order attribute from BOTH consumers and they will be invoked in the order they appear in the XML.
    2. Configure the XPath splitter as a normal splitter, which does support order...

      <int:splitter id="salesTransSplitter" order="1"
                 input-channel="salesInputChannel"
                 output-channel="splitterOutChannel" order="1">
          <bean class="org.springframework.integration.xml.splitter.XPathMessageSplitter">
              <constructor-arg value="/sales_transactions/trans" />
          </bean>
      </int-xml:xpath-splitter>