Nav

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.

  1. Open a new text file, and create policy, before, and pointcut elements.

    • Create a <policy>, id, and policyName elements to track the policy for analytics.


         
      
1
2
3
<policy xmlns="http://www.mulesoft.org/schema/mule/policy"
        id="{{policyId}}"
        policyName="Regex Filter"

+ * Add A before section to execute on every request to the API before the actual API services are called. The after 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. {{queryParamm}} 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

+


         
      
1
…​ <!-- 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 the mypolicy.xml example policy configuration file.