Hi All, I have populated some value in cache, now i am trying to get that value in lookup policy with GET resource. I put the following response tag in the GET resource,
<Response> <Step> <Name>JavaScript-1</Name> </Step> <Step> <Name>Assign-Message-1</Name> <Condition>(itemFound == false)</Condition> </Step> </Response> <Condition>(proxy.pathsuffix MatchesPath "/{id}") and (request.verb = "GET")</Condition>
In above code, when the cache value is found i successfully call the java script policy JavaScript-1 and when the cache value is not found then call the assign message policy Assign-Message-1 to generate some error response.
Now i want to load some data from XYZ proxy endpoint instead of returning error message with Assign-Message-1 policy, in case when the cache value is not found, as above.
How can i achieve this ?
I have already tried another approach by calling the expected target endpoint corresponding to XYZ endpoint, in Route tag, as,
<RouteRule name="default"> <Condition>(itemFound == false)</Condition> <TargetEndpoint>xyz-target</TargetEndpoint> </RouteRule>
But it did not work.
Any help to this question would be appreciated.
The approach of using a condition on the RouteRule should work.
Maybe you have multiple RouteRules? These are evaluated in order. The first RouteRule that has a Condition that evaluates to true, or has no condition at all, will be the RouteRule selected. For example, if you have this sequence:
<RouteRule name='r1'> <TargetEndpoint>target1</TargetEndpoint> </RouteRule> <RouteRule name='r2'> <TargetEndpoint>target2</TargetEndpoint> <Condition>itemFound = false</Condition> </RouteRule>
...then the second RouteRule (r2) will never be employed. The first will always run, regardless of the state of itemFound.
The second thing you need to look out for: where in the request & response flow is the itemFound context variable being set ? I see in your sample code that you are testing it in the Response flow. The response flow executes AFTER a RouteRule has been evaluated and executed. Maybe you are clear on this, but I thought I'd mention it.
Finally, I don't see any Cache Lookup policy at all. Maybe that is occurring in the preflow. With a little more context, we'd be clearer on what you've got configured. Right now there are a few open questions.
----
The other alternative, instead of RouteRules, is using a ServiceCallout. It's the same idea but the analytics will be different.
Thanks Dino for your reply. I further researched the case, now i just applied the Response Policy on this.