Kiran Kumar
Kiran Kumar

Reputation: 788

Unable to access header value in spring integration router int:mapping value

unable to access headers in the value attribute of router using like below

<int:router input-channel="route_profile"  expression="#jsonPath(payload, '$.entity')">
        <int:mapping value="headers.userId" channel="toWeb_send"/>
        <int:mapping value="headers.otherId" channel="find_preferences"/>
    </int:router>

Any thing here I am doing wrong.

Upvotes: 0

Views: 135

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121337

The expression is not what expected in that value attribute:

 <xsd:attribute name="value" type="xsd:string">
      <xsd:annotation>
          <xsd:documentation>
            A value of the evaluation token that will be mapped to a channel reference
            (e.g., mapping value='foo' channel='myChannel')
            </xsd:documentation>
        </xsd:annotation>
 </xsd:attribute>

This value is exactly what the mentioned top-level expression returns.

So, let's imaging your expression="#jsonPath(payload, '$.entity')" may return foo or bar, therefore the mapping must be like:

<int:mapping value="foo" channel="toWeb_send"/>
<int:mapping value="bar" channel="find_preferences"/>

If there is some logic around those headers, they have to be included in the expression evaluation. Or you may choose some other way to calculate the routing key.

Upvotes: 1

Related Questions