Mulesoft with Java Plugin
  • 23 Jan 2023
  • 4 Minutes to read

Mulesoft with Java Plugin


Mulesoft is an integration platform that help different businesses connect their data, devices, and applications for both cloud computing and on-premise deployments. Mulesoft's Anypoint Platform™ is a solution for API-led connectivity that creates an application network of apps, data, and devices for both on-premise and cloud deployments. Traceable provides a Java policy that can help you in protecting your APIs. You can attach the Traceable policy to any API registered on the Anypoint platform for security and monitoring purpose. The following diagram shows the high-level deployment of Traceable policy in your environment. 


Before you begin

Before proceeding to attach Traceable policy to an API on your Mulesoft Anypoint Platform, make a note of the following points:

  • Maven (mvn) must be installed.
  • Java 8 must be installed.
  • You should have access and permission to upload artifacts to Mulesoft exchange in your organization's Mulesoft Anypoint Platform account.
    Note
    To upload Traceable's custom policy to Mulesoft Exchange, you must have the exchange contributor's role assigned to you. For more information, see Uploading a Custom Policy to Exchange.
  • In your Maven installation directory, update the settings.xml file with your Exchange credentials.
    ActionScript 
    <?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>
    myusername and mypassword are your username and password to log in to Mulesoft account.
  • Keep the IP address of your Traceable agent handy. You would need this IP address to configure the Traceable's Mulesoft policy.

The process to attach Traceable's policy consists of two steps:

  1. Download the policy from Traceable's download site and then upload to Mulesoft's Exchange
  2. Attaching the policy to the API in Mulesoft.

Step 1 — Download the Java policy and upload to Mulesoft Exchange

Complete the following steps to download and unzip Traceable's Java policy:

  1. Navigate to Traceable's download site and then navigate to agent > mulesoft-java-plugin > latest.
  2. Unzip the downloaded file.
  3. Change directory to Mulesoft policy directory.
    ActionScript
    cd traceable-mule-policy
  4. Install the Traceable extension to your local Maven. Enter the following command:
    ActionScript
    mvn install:install-file -Dfile=$(ls | grep traceable-mule-extension) -DgroupId=ai.traceable.agent -DartifactId=traceable-mule-extension -Dversion=1.0.0 -Dclassifier=mule-plugin -Dpackaging=jar -DgeneratePom=true
  5. Navigate to Traceable policy.
    ActionScript
    cd traceable-java
  6. Update the groupId in pom.xml file to your Mulesoft organization's ID.
    ActionScript
    <?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>
    
    <!--UPDATE GROUP ID-->
        <groupId>4c2d42c8-910d-42fe-8f21-bc76f21ef3fe</groupId>
        <artifactId>traceable</artifactId>
        <version>1.15.0</version>
  7. Deploy the Traceable policy. Enter the following command:
    ActionScript
    mvn clean deploy
  8. Verify in your Mulesoft Anypoint Platform Exchange whether Traceable policy is present or not.

Upload policy to Mulesoft Exchange using Connected App credentials

There is an alternative method to upload the Traceable policy to Mulesoft Exchange using Connected App credentials. You can choose either this method or the one described in the previous section. 

MuleSoft Connected Apps is a feature within the MuleSoft Anypoint Platform that allows users to create and manage connections to external systems and services, such as SaaS applications, databases, and web services. These connections can then be used in MuleSoft's integration solutions, such as APIs and integrations, to facilitate communication and data exchange between different systems. By using Connected Apps, developers can quickly and easily connect to a wide variety of systems and services without the need to manually configure and manage the connections. Additionally, Connected Apps can be easily shared and reused across different projects and teams, making it easier to maintain and manage the connections.

Mulesoft Connected Apps are usually used in integration solutions, such as APIs and integrations, to facilitate communication and data exchange between different systems. It also provides a way to manage the connections and share them across teams.

Complete the following steps:

  1. Navigate to Traceable's download site and then navigate to agent > mulesoft-java-plugin > latest.
  2. Unzip the downloaded file.
  3. Change directory to Mulesoft policy directory.
    ActionScript
    cd traceable-mule-policy
  4. Install the Traceable extension to your local Maven. Enter the following command:
    ActionScript
    mvn install:install-file -Dfile=$(ls | grep traceable-mule-extension) -DgroupId=ai.traceable.agent -DartifactId=traceable-mule-extension -Dversion=1.0.0 -Dclassifier=mule-plugin -Dpackaging=jar -DgeneratePom=true
  5. Navigate to Traceable policy.
    ActionScript
    cd traceable-java
  6. Update the groupId in pom.xml file to your Mulesoft organization's ID.
    ActionScript
    <?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>
    
    <!--UPDATE GROUP ID-->
        <groupId>4c2d42c8-910d-42fe-8f21-bc76f21ef3fe</groupId>
        <artifactId>traceable</artifactId>
        <version>1.15.0</version>
  7. Build the Traceable policy. Enter the following command:
    ActionScript
    mvn clean install
  8. Fetch a bearer token using the credentials connected app, client ID, and secret. client_id and client_secret are the ID and secret of the Connected App.
    ActionScript
    curl --location --request POST https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'client_id=' \
    --data-urlencode 'client_secret=' \
    --data-urlencode 'grant_type=client_credentials'
  9. Publish the policy by running the following. Make sure to enter all the values in the <> brackets. The traceable_version is the version of Traceable's Mulesoft policy.
    ActionScript
    curl -v \
      -H 'Authorization: bearer ' \
      -H 'x-sync-publication: true' \
      -F 'files.pom=@/path/to/traceable-mule-policy/traceable/pom.xml' \
      -F 'files.mule-policy.jar=@/path/to/traceable-mule-policy/traceable/target/traceable--mule-policy.jar' \
      -F 'files.policy-definition.yaml=@/path/to/traceable-mule-policy/traceable/traceable.yaml' \
    https://anypoint.mulesoft.com/exchange/api/v2/organizations/<org_id>/assets/<org_id>/traceable/<traceable_version>
  10. Verify in your Mulesoft Anypoint Platform Exchange whether Traceable policy is present or not.

Step 2 – Install Mulesoft agent as a policy

Complete the following steps:

  1. Login to your Anypoint Platform and navigate to API Manager.
  2. Select the API to which you wish to apply the Traceable policy.traceable_mulesoft_select_api
  3. Navigate to the Policies menu and click on Add Policy.traceable_mulesoft_add_policy(1)
  4. Search and select the Traceable policy and click on Next.
  5. Configure the various options and click on Apply.

    Add the reporting endpoint of Traceable Platform Agent. If Trace Reporter Type is OTLP (default), then the reporting endpoint should be http://HOST_IP:4318/v1/traces. If the Trace Reporter type is ZIPKIN, then it should be http://HOST_IP:9411.


Verification

To verify whether the policy successfully attached to the API in Mulesoft, navigate to Traceable platform. Click on Administration > Data Collection > Tracing agents. Check if Mulesoft agent is displayed and the status is active. You can further check for spans in API Analytics or API Activity under API Catalog.


Upgrade and uninstall

To upgrade the policy, follow the steps in mentioned in Step -1 section to add the new policy to Mulesoft's Exchange. After you have added the new policy to Mulesoft Exchange, complete the following steps:

  1. Navigate to the API for which you want to upgrade the policy.
  2. Click on the Policies option.
  3. Click on the menu item as shown below. 
  4. Click on Check for updates to update the policy.

If you wish to uninstall the policy, click on Remove policy.


Was this article helpful?

What's Next