Results 1 to 3 of 3

Thread: xpath-splitter and empty xpath result

  1. #1
    Join Date
    Nov 2010
    Location
    St-Petersburg, Russia
    Posts
    33

    Default xpath-splitter and empty xpath result

    Hello.

    My goal is to process some XML like
    Code:
      <items>
        <item>value1</item>
        <item>value2</item>
        <item>value3</item>
      </items>
    And convert it to a List of my beans that could be created with static MyBean.create(String).
    Here is a context fragment:
    Code:
        <int:chain input-channel="..." output-channel="...">
            <int-xml:xpath-splitter>
                <int-xml:xpath-expression expression="/items/item" />
            </int-xml:xpath-splitter>
            <int-xml:xpath-transformer evaluation-type="STRING_RESULT" xpath-expression="/" />
            <int:transformer expression="T(MyBean).create(payload)" />
            <int:aggregator />        
        </int:chain>
    It works quite well when the input message contains some items. But I'm failed to get an empty list when the message doesn't contains any items.
    As far as I understand from code, XPathMessageSplitter throws an exception when the result collection is empty. Is there any way to work around that?

    Regards,
    -- Alexey

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,146

    Default

    Add an xpath-filter upstream of the splitter...

    Code:
        <int:chain input-channel="..." output-channel="...">
            <int-xml:xpath-filter>
                <int-xml:xpath-expression expression="/items/item" />
            </int-xml:xpath-filter>
            <int-xml:xpath-splitter>
                <int-xml:xpath-expression expression="/items/item" />
            </int-xml:xpath-splitter>
            <int-xml:xpath-transformer evaluation-type="STRING_RESULT" xpath-expression="/" />
            <int:transformer expression="T(MyBean).create(payload)" />
            <int:aggregator />        
        </int:chain>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Nov 2010
    Location
    St-Petersburg, Russia
    Posts
    33

    Default

    I'm using a gateway around that chain and it is not happy, when filter gobbles the request. I've added an xpath-router to check if there are any items or not. If no, I manually generate an empty list.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •