2
votes

I need to take an incoming XML message, which contains repeating elements, and split these into separate messages for onward processing. I then need to recombine the results and respond over HTTP.

I'm using a Splitter node and XPath for the first step. However, it only accesses the first element in the XML and also does not preserve the XML to the next stage. I've tried the example from the documentation, but it has the same output.

I'm running Mule 3.6.1 CE from within Anypoint Studio.

NB order of processing of the elements will be important, hence I don't just want to do a Scatter-Gather.

Here's my sample XML:-

<?xml version="1.0" encoding="UTF-8"?>
<itm:ItemList
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:itm="http://schemas.goochjs.org/item-v1"
        xsi:schemaLocation="http://schemas.goochjs.org/item-v1 item-v1.xsd">

    <itm:Item sequence="1" action="create">
        <itm:Thing type="something">
            <itm:Description>Something</itm:Description>
        </itm:Thing>

        <itm:Thing type="anything">
            <itm:Description>Something else</itm:Description>
        </itm:Thing>
    </itm:Item>

    <itm:Item sequence="2" action="update">
        <itm:Thing type="anything">
            <itm:Description>A wotsit</itm:Description>
        </itm:Thing>
    </itm:Item>

    <itm:Item sequence="2" action="create">
        <itm:Thing type="something">
            <itm:Description>A doohinky</itm:Description>
        </itm:Thing>
    </itm:Item>

    <itm:Item sequence="3" action="delete">
        <itm:Thing type="something">
            <itm:Description>A different doohinky</itm:Description>
        </itm:Thing>
    </itm:Item>
</itm:ItemList>

Here's my code:-

<?xml version="1.0" encoding="UTF-8"?>

<mule
    xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
    xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
    <http:listener-config name="splitter-endpoint" host="0.0.0.0" port="8081" basePath="/splitter" doc:name="HTTP Listener Configuration"/>
    <mulexml:namespace-manager includeConfigNamespaces="true">
        <mulexml:namespace prefix="itm" uri="http://schemas.goochjs.org/item-v1"/>
    </mulexml:namespace-manager>

    <flow name="mule-splitter-aggregatorFlow">
        <http:listener config-ref="splitter-endpoint" path="/" allowedMethods="post" doc:name="HTTP"/>
        <splitter expression="#[xpath3('/itm:ItemList/itm:Item')]" doc:name="Splitter"/>
        <logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

And this is the output in the log:-

INFO  2015-03-19 10:48:17,440 [[mule-splitter-aggregator].splitter-endpoint.worker.01] org.mule.routing.ExpressionSplitter: The expression does not evaluate to a type that can be split: java.lang.String
INFO  2015-03-19 10:48:17,441 [[mule-splitter-aggregator].splitter-endpoint.worker.01] org.mule.api.processor.LoggerMessageProcessor: 

            Something



            Something else

What am I missing? I've tried adding various different transformers before the split (e.g. Object to XML as suggested here) but to no avail.

1

1 Answers

4
votes

Try forcing the xpath expression to return a NODESET:

<splitter expression="#[xpath3('/itm:ItemList/itm:Item', payload, 'NODESET')]"
        doc:name="Splitter" />