Mule splitter using regex returned no results

2019-09-06 20:25发布

问题:

I'm trying to split a csv file on lines. For this, I've tried alternatively with the following splitters on my flow:

<splitter expression="#[regex('^')]" doc:name="Splitter"/>

<splitter expression="#[regex('\n')]" doc:name="Splitter"/>

<splitter expression="#[regex('.*')]" doc:name="Splitter"/>

However, though the file has many lines, I'm getting the following message on the logs:

Splitter returned no results. If this is not expected, please check your split expression

回答1:

Finally, I found a tutorial here with the solution: http://www.dotnetfunda.com/articles/show/2070/using-mule-studio-to-read-csv-comma-seperated-value-data-from-fileinbo

The splitter has to be configured this way:

    <splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter" />

And that requires the following element to be included on the flow:

<configuration doc:name="Configuration">
    <expression-language autoResolveVariables="true">
        <import class="org.mule.util.StringUtils" />
    </expression-language>
</configuration>


回答2:

This expression works for splitting CSV file :-

<splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter_For_MultipleRow"/>

And if your CSV files have a column headers like Name, Age etc .. you can use this :-

<splitter expression="#[rows=StringUtils.split(message.payload, '\n\r');ArrayUtils.subarray(rows,1,rows.size())]" doc:name="Splitter_For_MultipleRow"></splitter>