GettingStarted With123
GettingStarted With123

Reputation: 427

Mule 3 - how do I iterate over each header?

I am trying to find if any of the header value contains a certain value say Moscow. Note - I would NOT know the names upfront of headers so I cannot search by header name ( as an example ) :

message.inboundProperties.Accept

So I need a way to iterate over whatever are the incoming headers and then check their values . I am struugling how to achieve this in Mule 3 using Dataweave 1 ?

Upvotes: 0

Views: 131

Answers (1)

aled
aled

Reputation: 25664

In DataWeave 1.x (Mule 3.x) inboundProperties is an object (a collection of key-values) that contains a key with the name of the property. You can use any technique that you would use to do the same search in any other object. For example using the pluck operator to get a list of values in the object, map the list to check if the element contains the desired value, then reduce the list of resulting booleans by using a logical or operation.

It could be similar to this:

((inboundProperties pluck $) map ($ contains "Moscow")) reduce ((item, acc=false) -> acc or item)

I don't have access to test it at the moment but hopefully you get the idea.

Then I recommend that you implement it as a function for easier use so you can pass the value to search as a parameter.

DataWeave 2.x certainly has much better functions to implement this kind of expressions more easily.

Upvotes: 2

Related Questions