Contact Free trial Login

Uploading a Custom Policy to Exchange

Exchange provides an API to publish or consume assets using a Maven client. You must have a unique artifact name and organization ID to publish your asset.
See the Maven facade API Exchange asset for more details.

API Manager lists custom policies published as assets of your organization.

Deploying a Policy Created Using the Maven Archetype

When you create your custom policy project using the provided Maven archetypes, all the necessary plugins for uploading the policy to Exchange are already defined for you.
See the Setting up a project with the archetype instructions for more information.

You must configure your Exchange credentials:

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

    <?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>
  2. 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.

Deploying a Policy Created Without Using the Maven Archetype

If you chose not to create your custom policy project using the provided Maven archetypes, you need to manually set up your Exchange deployment configurations:

  1. In Anypoint Platform, search your organization’s ID to use in the following steps.

    • Go to 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.

  2. Go to your pom.xml

  3. Replace the groupId with the organization’s ID from the previous step.

    <groupId>{orgId}</groupId>
  4. Add the following properties replacing the {orgId} for the organization’s id from the previous steps:

    <properties>
      <exchange.url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{OrgId}/maven</exchange.url>
      <mule.maven.plugin.version>3.2.0</mule.maven.plugin.version> <!-- check for last available version -->
    </properties>
  5. Additonally, in your pom.xml file, define Exchange as a repository:

    <repository>
    	<id>exchange-server</id>
    	<name>MuleSoft Exchange Environment</name>
    	<url>${exchange.url}</url>
    	<snapshots>
    		<enabled>true</enabled>
    	</snapshots>
    </repository>
  6. Set up your Exchange server as a distribution management:

    <distributionManagement>
        <repository>
            <id>exchange-server</id>
            <name>Corporate Repository</name>
            <url>${exchange.url}</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>
  7. Additionally, add the following build plugins:

    • Mule Maven Plugin: Verifies that all necessary files are present and it is require to correctly package policy.

    • Maven Deploy Plugin: Communicates with the exchange repository, and uploads the policy jar and yaml files.

      <build>
          <plugins>
              <plugin>
                  <groupId>org.mule.tools.maven</groupId>
                  <artifactId>mule-maven-plugin</artifactId>
                  <version>${mule.maven.plugin.version}</version>
                  <extensions>true</extensions>
              </plugin>
              <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>exchange-server</repositoryId>
                              <url>${exchange.url}</url>
                              <file>${project.basedir}/${project.artifactId}.yaml</file>
                              <generatePom>false</generatePom>
                              <groupId>${project.groupId}</groupId>
                              <artifactId>${project.artifactId}</artifactId>
                              <version>${project.version}</version>
                              <packaging>yaml</packaging>
                              <classifier>policy-definition</classifier>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      </build>

      And the following plugin repository

      <pluginRepositories>
          <pluginRepository>
              <id>mule-plugin</id>
              <name>Mule Repository</name>
              <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
          </pluginRepository>
      </pluginRepositories>
  8. Set up your Exchange credentials in the settings.xml file in your Maven .m2 directory:

    <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>exchange-server</id>
           <username>myusername</username>
           <password>mypassword</password>
         </server>
      </servers>
    </settings>
  9. Finally, deploy the policy using maven clean deploy.

    The IDs defined for your Exchange repositories must match.