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. API Manager lists custom policies published as assets of your organization.

For more information about the Exchange Maven Facade asset, see Exchange Maven Facade.

Prerequisites

To upload a custom policy to Exchange, you must have the Exchange Contributors role.

Deploying a Policy Created Using the Maven Archetype

If you create your custom policy project using the provided Maven archetype, the plugins necessary to upload the policy to Exchange are already defined for you. See Setting Up a Project with the Archetype.

To deploy a policy created using the Maven archetype:

  1. In your Maven .m2 directory, update the settings.xml file 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>exchange-server</id>
           <username>myusername</username>
           <password>mypassword</password>
         </server>
      </servers>
    </settings>
    For information about how to authenticate using a token rather than using credentials, see Publish and Consume Federated Assets.
  2. Run mvn clean 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 did not create your custom policy project using the provided Maven archetype, you must manually define the Exchange deployment configuration.

To deploy a policy created without using the Maven archetype:

  1. In Anypoint Platform, find the organization ID to use as follows:

    1. Go to Access Management > Organization.

    2. Click the name of your organization.

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

  2. Update your pom.xml file as follows:

    1. Replace the groupId value with the organization ID from the preceding step:

      <groupId>{orgId}</groupId>
    2. Add the following properties and replace {orgId} with the organization ID from the preceding step:

      <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>
    3. 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>
    4. Set up your Exchange server as a distribution management repository:

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

      • Mule Maven plugin: Verifies that all necessary files are present and that all requirements are met to correctly package the 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>
    6. Add 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>
  3. In your Maven .m2 directory, update the settings.xml file with your Exchange credentials:

    <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>
    For information about how to authenticate using a token rather than using credentials, see Publish and Consume Federated Assets.
  4. Deploy the policy using the mvn clean deploy command.

    The IDs defined for your Exchange repositories must match.

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

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub