Search code examples
springrouterspring-integrationspring-elhtml-escape-characters

Spring Expression Language equivalent for \r, \n, \t etc


I am using Spring Integration. I get a string (payload) like below:

<Element>
<Sub-Element>5</Sub-Element>
</Element>

I need to test if above string starts with <Element><Sub-Element> which is actually <Element>\r\n <Sub-Element>.

<int:recipient-list-router id="customRouter" input-channel="routingChannel">
    <int:recipient channel="channel1" selector-expression="payload.startsWith('&lt;Element&gt;&lt;Sub-Element&gt;')"/>
    <int:recipient channel="channel2" selector-expression="!payload.startsWith('&lt;Element&gt;&lt;Sub-Element&gt;')"/>
</int:recipient-list-router>

Ideally the first router should pass the test but in this case its failing. Can anyone help me finding out what is the SpEL equivalent of \r \n etc ?


Solution

  • Thanks Gary. So the working list-recipient-router looks like

    Either

    <recipient selector-expression="payload matches '(?s)&lt;Element&gt;(\s*)&lt;Sub&gt;(.*)'" channel="channel1"/>
    <recipient selector-expression="!(payload matches '(?s)&lt;Element&gt;(\s*)&lt;Sub&gt;(.*)')" channel="channel2"/>
    

    Or

    <recipient selector-expression="payload matches '(?s)&lt;Element&gt;(.*)&lt;Sub&gt;(.*)'" channel="channel1"/>
        <recipient selector-expression="!(payload matches '(?s)&lt;Element&gt;(.*)&lt;Sub&gt;(.*)')" channel="channel2"/>
    

    May keep captures () or may not. Both works.