ScriptableFilter
Processes requests and responses by executing a Groovy script. Executed scripts must return one of the following:
To execute the next element in a chain (a filter or a handler), the script
must call the expression next.handle(context, request)
. If the script doesn’t
call next.handle(context, request)
, the chain flow breaks and the script has
to build and return its own response by calling one of the following expressions:
-
return myResponse
-
return newResultPromise(myResponse)
Actions on the response returned from the downstream flow must be performed in the Promise’s callback methods.
You can find more information about script properties, available global objects, and automatically imported classes in Scripts. You can find more information about creating scriptable objects in Studio in Scripts in Studio and Configure scriptable throttling.
Usage
{
"name": string,
"type": "ScriptableFilter",
"config": {
"type": configuration expression<string>,
"file": configuration expression<string>, // Use either "file"
"source": [ string, ... ], // or "source", but not both.
"args": map,
"clientHandler": Handler reference
}
}
Properties
You can find more information about properties for ScriptableFilter in Scripts.
Examples
You can find an example scriptable filter that recovers policy advices from AM
in the failureHandler
property of PolicyEnforcementFilter.