Contact Free trial Login

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.

  2. Create policy, ID, and policyName elements to track the policy for analytics.

    <policy xmlns="http://www.mulesoft.org/schema/mule/policy"
            id="{{policyId}}"
            policyName="Regex Filter"
  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. Save the file using a .xml extension.

Download Example Files

Download mypolicy.xml example policy configuration file.

Was this article helpful?

๐Ÿ’™ Thanks for your feedback!

Edit on GitHub