Mule SDK Java Extension Part I

Ashish Jain
Another Integration Blog
4 min readJul 9, 2023

Another way of writing reusable Java code across an organization or organizations can be a basic implementation of the Mule Extension operation. If you are a service based firm creating utilities in the form of extensions to be used for your clients, or if you are a product based firm that creates utilities to be used across all products in your organization, the Mule SDK Java Extension can be a way to go.

Mule Extension

Here in this story we will write a basic Mule Extension operation or connector operation with minimum prerequisites. We will only be focusing on creating an operation in this edition.

SDK Modules can be built using Maven Archetypes and I have simplified its phases in form of abbreviation to easily learn (SCoDA):

(S) Setting up the Project

(Co) Code or Develop

(D) Deploy

(A) Apply

Let us understand all its phases:

Setting Up The Project (S):

Use Maven Archetype to create a Custom Extension

Add below snippets in your Maven “Settings.xml”:
Profiles Section: For accessing and downloading archetype contents and dependencies.

Maven Settings.xml Profiles

Servers Section: For uploading and deploying asset into your AnyPoint Platform exchange. These credentials should be AnyPoint Platform Credentials

Maven Settings.xml Servers

To download Policy Project use below command in Command Prompt

mvn org.mule.extensions:mule-extensions-archetype-maven-plugin:generate

Fill in the prompts:
Enter the name of the extension (empty for default)
Enter the extension’s groupId (empty for default)
Enter the extension’s artifactId (empty for default)
Enter the extension’s version (empty for default)
Enter the extension’s main package (empty for default)

The project will get downloaded with below structure

Mule Java SDK Project Structure

Code or Develop(Co):

Add your classes to the project in src/main/java.

Sample Custom Class

Call your classes in Operations class to create a Mule Operation as below:

Project Operations

If no Connector Configuration is required the you can comment other default operations as below:

Deploy(D):

Add below snippet to your POM file and replace ${orgId} with your organization ID

<distributionManagement>
<repository>
<id>exchange-server</id>
<name>Corporate Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/${orgId}/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>

Your Project group Id should also be your OrgId. Hence your POM file looks like below:

Distribution Management

Now open command prompt in your Projects root folder and execute below command:
Note: “-DskipTests” is to ignore the default automated tests comes with the Project structure

mvn deploy –DskipTests

Once the Build is success, you will be able to see the Extension as a connector in Exchange like below:

Connector in Exchange

Apply (A)

This Connector can be applied to any API. Add the newly created connector from Exchange and the operations will be available as a Mule Component.

Using Custom Connector

Bingo ! We have created a basic Mule Extension to use our custom code directly from exchange and share across Anypoint Platform.

We will see more in upcoming parts of this edition.

Please let me know if you have any comments, suggestions, or just general feedback for me!

--

--

Ashish Jain
Another Integration Blog

I have vast experience in IT with specialization in middleware and integration. Have a passion to learn new things and solve any given problem in optiized way