I am setting up a new header from the "Assign Message" policy using a variable.
I want to have some conditional flow (to do Null check) before setting up the header.
For Eg:
If (accesstoken.user-foo != null) {
<Set>
<Headers>
<Header name="FEContext">{accesstoken.user-FEContext}</Header>
</Headers>
</Set>
}
How can I do this ?
Solved! Go to Solution.
You can't set headers or variables under a specific condition within AssignMessage policy. But you can achieve this in one of the following ways:
Regards,
Amar
You can't set headers or variables under a specific condition within AssignMessage policy. But you can achieve this in one of the following ways:
Regards,
Amar
To elaborate what Amar told, you should have a your code looking like this:
1. Your proxy flow should look like this:
<Step> <Name>JsCall.CheckNullValueofFoo</Name> </Step> <Step> <Condition>(isNull = "false")</Condition> <Name>Assign.Headers</Name> </Step>
2. JsCall.CheckNullValueofFoo Policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Javascript timeLimit="0" enabled="true" continueOnError="false" async="false" name="JsCall.CheckNullValueofFoo"> <FaultRules/> <Properties/> <ResourceURL>jsc://CheckNullValueofFoo.js</ResourceURL> </Javascript>
3. JsCall.CheckNullValueofFoo.js
var isNull = true; var user-foo = ""; var user-foo = context.getVariable("accesstoken.user-foo); if (user-foo) context.setVariable("isNull",false);
4. Assign.Headers
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage enabled="true" continueOnError="true" async="false" name="Assign.Headers"> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" type="request" /> <Set> <Headers> <Header name="FEContext">{accesstoken.user-FEContext}</Header> </Headers> </Set> </AssignMessage>
Hope this helps