Nav

To Upload a Policy to Exchange (Nov 2017)

Custom policies need to be published to Exchange so users can obtain and apply them to APIs. API Manager lists custom policies published as assets of the Organization.

Anypoint Exchange provides a Maven facade that enables Maven clients to publish and consume assets using Maven and publish custom policies to Exchange.

You must have a unique artifact name and organization ID to publish your asset.

  1. Add the Maven facade as a repository in the distribution management section of your project’s POM file:

    <distributionManagement>
       <repository>
           <id>Repository</id>
           <name>Corporate Repository</name>
           <url>${exchange.url}</url>
           <layout>default</layout>
       </repository>
    </distributionManagement>
  2. Add a property called exchange.url in the properties section of your project’s POM file:

    <properties>
       <mule.maven.plugin.version>3.0.0</mule.maven.plugin.version>
       <exchange.url>
          https://maven.anypoint.mulesoft.com/api/v1/organizations/<organization id>/maven
       </exchange.url>
    </properties>
  3. Get your organization ID from Access Management > Organization:

    • Click the name of your organization.

    • Copy the UUID from the browser address. For example, copy 2a4b93c3-7899-4ea7-9374-f787744d8784 from the URL.

  4. Replace the placeholder <organization id>.

  5. Add the following maven plugin to the plugins section of your project POM file. This enables the upload of the YAML and JAR files:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-deploy-plugin</artifactId>
       <executions>
           <execution>
               <id>upload-template</id>
               <phase>deploy</phase>
               <goals>
                   <goal>deploy-file</goal>
               </goals>
               <configuration>
                   <repositoryId>Repository</repositoryId>
                   <url>${exchange.url}</url>
                   <file>${project.basedir}/${project.artifactId}.yaml</file>
                   <generatePom>false</generatePom>
                   <artifactId>${project.artifactId}</artifactId>
                   <groupId>${project.groupId}</groupId>
                   <version>${project.version}</version>
                   <packaging>yaml</packaging>
                   <classifier>policy-definition</classifier>
               </configuration>
           </execution>
       </executions>
    </plugin>
  6. Optionally, define the <name> and <description> in the project POM to set the name and description of the Exchange asset. Also define tags in Exchange by adding the <tags> attribute inside the properties section of the POM.

  7. Update the settings.xml file in your Maven .m2 directory with your Exchange credentials.

    Example settings.xml file

    
              
           
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <servers>
        <server>
          <id>Repository</id>
          <username>myusername</username>
          <password>mypassword</password>
        </server>
      </servers>
    </settings>
  8. Run mvn deploy to publish the policy to Exchange.

    The custom policy is now available for you to apply to APIs that belong to the specified organization.