3

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>   
Jesús Chacón
  • 187
  • 1
  • 9

1 Answers1

1

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>   
    
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks Gary, but i'm getting this exception from the Splitter. Caused by: org.xml.sax.SAXParseException; lineNumber: 97; columnNumber: 70; cvc-complex-type.3.2.2: No está permitido que el atributo 'order' aparezca en el elemento 'int-xml:xpath-splitter'. The "order" Attribute is not allowed in xpath-splitter. Look at the edit in my post for a config sample. By the way im using Spring Integration 4.1.6 RELEASE. – Jesús Chacón Dec 04 '15 at 13:41
  • Sorry about that; it's a bug [JIRA here](https://jira.spring.io/browse/INT-3902); see my edit for a couple of work-arounds. – Gary Russell Dec 04 '15 at 14:08