You can use the assign-attributes
policy to set variables such as request attributes, message attributes and other execution context attributes.
When you are using this policy on the message request or response, the attribute will be available in the message attribute list and not on the context one.
You can use it to retrieve initial request attributes after Transform headers
or Transform query parameters
policies and reuse them in other policies (Dynamic routing
, for example).
You can configure the policy with the following options:
Property | Required | Description | Type | Default |
---|---|---|---|---|
scope |
only for v3 engine |
The execution scope ( |
string |
|
attributes |
X |
List of attributes |
See Attribute |
Property | Required | Description | Type | Default |
---|---|---|---|---|
name |
X |
attribute name |
string |
|
value |
X |
attribute value (can be EL) |
string |
Let’s say we want to inject request attributes into the context attributes.
"assign-attributes": {
"attributes": [
{
"name": "initialContentTypeHeader,
"value": "{#request.headers['Content-Type']}"
},
{
"name": "initialFooParamHeader,
"value": "{#request.params['foo']}"
}
]
}
To extract the request attributes you can use the following syntax:
Get the content-type header:
{#context.attributes['initialContentTypeHeader']}
Get the foo query param:
{#context.attributes['initialFooParamHeader']}
You can also be more general and put complex objects into the context attributes:
"assign-attributes": {
"attributes": [
{
"name": "initialRequest,
"value": "{#request}"
}
]
}
To extract the request attributes you can use the following syntax:
Get the content-type header:
{#context.attributes['initialRequest'].headers['content-type']}
Get the foo query param:
{#context.attributes['initialRequest'].params['foo']}