<policy xmlns="http://www.mulesoft.org/schema/mule/policy"
id="{{policyId}}"
policyName="Regex Filter"
Create the Custom Policy Configuration File
This procedure describes how to create a custom policy configuration file. At the end of this procedure, you can download the complete file.
-
Open a new text file, and create policy, before, and pointcut elements.
-
Create policy, ID, and policyName elements to track the policy for analytics.
-
Add a
before
section to execute on every request to the API before the actual API services are called. Theafter
section is not needed; return results need no processing. -
Include a filter element in the before section that references an element named Expression. This filter element has a name property that matches the referenced element.
The expression parameter specifies the filtering conditions and the targeted element to filter. The YAML file defines these parameters, which are wrapped in
{{curly brackets}}
in the XML configuration file:{{regexFilter}}
is used as the filtering condition.{{queryParam}}
is used to construct expression that references the desired query parameter. -
Include a message filter, which is a standard Mule element, to filter the incoming request. This element does not actually define the filter logic, but references the Expression element that specifies the filter’s behavior.
-
Add an onUnaccepted property in the opening tag of the filter element in the before section references the policyViolation element.
... <!-- This executes right after the inbound endpoint of the application --> <before> <mule:message-filter xmlns:mule="http://www.mulesoft.org/schema/mule/core" onUnaccepted="policyViolation"> <mule:filter ref="Expression"/> </mule:message-filter> </before>
When the criteria specified by the filter is not matched, this property calls and executes the referenced element.
-
Save the file using a .xml extension.
Download Example Files
Download mypolicy.xml example policy configuration file.