Nav

Custom Policy Development Reference (Nov 2017)

To develop a custom policy, you need a maven project having the following structure:

custom policy structure

Where:

  • pom.xml meets the following requirements:

    • groupId = organization Id.

    • packaging = mule-policy.

      This value is a Mule custom value for policies provided by the mule-maven-plugin, so this plugin has to be present in the pom also.

  • mule-artifact.json exists for the mule-maven-plugin. This is the same file you need for Mule applications.

  • my-custom-policy.yaml exists to render the policy configuration UI.

    If this file is not provided, the policy won’t be able to be applied through API Platform’s UI.

  • template.xml

    The template represents the actual logic of the policy and Mule configuration that defines the policy behavior.

POM Configuration Example

The minimum required POM configuration is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

   <modelVersion>4.0.0</modelVersion>

   <groupId>bbd37829-003c-4f20-8888-3181b24e3384</groupId>
   <artifactId>my-custom-policy</artifactId>
   <version>1.0.0-SNAPSHOT</version>

   <packaging>mule-policy</packaging>

   <properties>
       <mule.maven.plugin.version>3.0.0</mule.maven.plugin.version>
   </properties>

   <build>
       <plugins>
           <plugin>
               <groupId>org.mule.tools.maven</groupId>
               <artifactId>mule-maven-plugin</artifactId>
               <version>${mule.maven.plugin.version}</version>
               <extensions>true</extensions>
           </plugin>
       </plugins>
   </build>
</project>

mule-artifact.json Example

{
 "name": "my-custom-policy-template",
 "minMuleVersion": "4.0.0",
 "requiredProduct": "MULE_EE",
 "classLoaderModelLoaderDescriptor": {
   "id": "mule",
   "attributes": {}
 },
 "bundleDescriptorLoader": {
   "id": "mule",
   "attributes": {
     "groupId": "bbd37829-003c-4f20-8888-3181b24e3384",
     "artifactId": "my-custom-policy",
     "version": "1.0.0-SNAPSHOT",
     "classifier": "mule-policy",
     "type": "jar"
   }
 }
}

my-custom-policy.yaml Example

id: my-custom-policy
name: My Custom Policy
supportedPoliciesVersions: '>=v1'
description: The custom policy description
category: Custom
type: syscustomtem
resourceLevelSupported: true
standalone: true
requiredCharacteristics: []
providedCharacteristics:
 - Some Characteristic
configuration: []