Access to the
message flow variable and its properties depends on the point within
the API Proxy Flow in which it is accessed. It is available in all contexts, whereas some objects,
response are not.
For example, in the error flow, the
response object is not available. You will not
be able to set response headers on the
if you are in the error flow. Instead, you can use one of the following:
You can use the AssignMessage policy to assign values, such as headers, to the response object. AssignMessage automatically handles the switch in context from request/response flow to error flow.
Another use case for the
message variable is to log response data in the
PostClientFlow with the MessageLogging policy. If you use the
you can seamlessly log response information following both success and error conditions in the
The following expression, however, will not work:
In this case, the
response variable is out of scope in the
error flow. (Note that, in a trace, this is visually indicated by variables shown with an equals
sign with a slash through it.)
<faultrules> <faultrule name="invalid_key_rule"> <step> <name>SetResponseHeaders</name> </step> <condition>(fault.name = "InvalidApiKey")</condition> </faultrule> </faultrules>
In the policy, code like the following sets the error/response header in any flow context:
context.setVariable('message.header.FOO-1', 'the header value');
You can reuse this same policy on the normal ProxyResponse flow and it will succeed because
message is available from all contexts.