Andres
Andres

Reputation: 10717

Splitter in Mule 3.2

I'm using a splitter in a Mule flow, as described on the answer to this question:

Mule splitter using regex returned no results

However, when I try to do something similar on Mule 3.2, I get the following error:

Line 27 in XML document from URL [file:/...] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'expression-language'. One of '{"http://www.mulesoft.org/schema/mule/core":annotations, "http://www.mulesoft.org/schema/mule/core":default-threading-profile, "http://www.mulesoft.org/schema/mule/core":default-dispatcher-threading-profile, "http://www.mulesoft.org/schema/mule/core":default-receiver-threading-profile, "http://www.mulesoft.org/schema/mule/core":default-service-threading-profile, "http://www.mulesoft.org/schema/mule/core":abstract-reconnection-strategy}' is expected. (org.mule.api.lifecycle.InitialisationException)

So, my questions are: Can the following element be used in Mule 3.2? And if not, which is the correct way to do it in that version?

<configuration>
    <expression-language autoResolveVariables="false">
        <import class="org.mule.util.StringUtils" />
    </expression-language>
</configuration>
<splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter" />

EDIT

Following @Ryan Carter's answer, I used the following:

<splitter evaluator="groovy" expression="payload.split('\n\r')" doc:name="Splitter" />

This works with Mule 3.4, but on Mule 3.2 seems to return an array which provokes the following warning, and a posterior error:

Splitter only returned a single result. If this is not expected, please check your split expression

EDIT 2

In Mule 3.2 you have to add the toList() function, to 'split' the array, that seems to be considered as a single object by this version.

Upvotes: 1

Views: 520

Answers (2)

Andres
Andres

Reputation: 10717

Got it:

<splitter evaluator="groovy" expression="payload.split('\n\r').toList()" doc:name="Splitter" />

Upvotes: 0

Ryan Carter
Ryan Carter

Reputation: 11606

It's not available in the 3.2 schema: http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd

expression-language wasn't added until 3.3.x : http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd

Until then you just have to fully qualify the Class. i.e. #[org.mule.util.StringUtils.split(message.payload, '\n\r')]

UPDATE To use the splitter in Mule 3.2 you will also need to specify an 'evaluator' attribute. The groovy evaluator would probably work best in this case:

Upvotes: 2

Related Questions