mitra-maven-auto-logo

Building Maven Plugins for Auto-Validation of WSO2 Artifacts

In this Tech ‘How to Guide’, Ayeshmantha Perera – Associate Software Engineer at Mitra Innovation describes his experience in developing Maven Plugins to validate WSO2 artifacts at build time.

As a preferred partner of WSO2, Mitra Innovation engages in integration projects using WSO2 products and technologies. To successfully build some of the integration projects, developers use the WSO2 Developer Studio to develop WSO2 artifacts and projects. These artifacts include various middleware components including ESB artifacts such as sequences, endpoints, local-entries etc, Data Services artifacts, GREG artifacts and so on.

With the increasing number of artifacts in a project, it is important to validate all the artifacts in use prior to deploying the artifacts into servers. These artifacts need to adhere to well defined naming standards. Some WSO2 artifacts such as synapse configurations should conform to industry best practices to define mediation flows. These standards may vary based on the project or client requirements.

At Mitra Innovation we developed two Maven Plugins to validate WSO2 artifacts during the build phase.

The Maven Plugins are:

1. ) WSO2 Car Validator Maven Plugin
2. ) WSO2 Synapse-Validator-Maven-Plugin

WSO2 Car Validator Maven Plugin

WSO2 artifacts are generated and packaged as a composite application archive (.car file) in the maven build by the maven-car-plugin. After all the artifacts are packaged, prior to deploying the artifacts to the WSO2 servers, our WSO2 validator plugin will validate all artifacts by referring to the generated artifact.xml file. The generated artifact.xml file contains the details of all the artifacts in the WSO2 composite application.

Design

The following is a high level architecture diagram of the WSO2 Car Validator Maven Plugin.

Fig 1 - High level architecture diagram of the WSO2 car validator plugin

(Fig 1: High level architecture diagram of the WSO2 Car Validator Maven Plugin)

The naming standards are defined as a set of regular expression rules for artifact file names.

The following is a sample configuration of wso2namingStandards.json file.

Fig 2 - Sample configurations of ‘wso2namingstandards.json’ file

(Fig 2: Sample configurations of ‘wso2namingstandards.json’ file))

How to use the plugin

To use this plugin, simply add the Car-Validator-Maven-Plugin to your Maven project (for execution in the installation phase) after all the artifacts are built and packaged in the maven package phase. In the configuration section of the plugin, we define the location of the WSO2 naming standards file (wso2namingStandards.json) which defines all the naming standards for artifacts and the artifact.xml file of the composite application.

Figure 3 below, displays a sample configuration of the car-validator-maven-plugin in the Maven project’s section.

Fig 3 - how to configure car-validator-maven-plugin in the maven project’s build section

(Fig 3: How to configure car-validator-maven-plugin in the Maven project’s section)

WSO2 Synapse Validator Maven Plugin

Synapse validation standards are based on WSO2 best practices for integration. The synapse best practices and guidelines help developers to avoid unnecessary mediation mistakes and errors that occur during mediation flows. It is necessary to automate the validation of WSO2 synapse artifacts – against WSO2 best integration patterns – prior to deploying the artifacts into the servers. As a solution for this requirement, we developed the WSO2 Synapse Validator Maven Plugin.

WSO2 artifacts are generated and packaged as a composite application archive (.car file). In the installation phase of Maven, the plugin we have developed will validate all the sequence artifacts in the project by identifying all the paths of the artifacts from artifact.xml, as well as reading the synapse sequences from the .xml files that are included in the path.

Design

Figure 4 below is a high level architecture diagram of the WSO2 Car Validator Maven Plugin.

Fig 4 - High Level architecture diagram of the wso2 car validator maven plugin

(Fig 4: High level architecture diagram of the WSO2 Car Validator Maven Plugin)

The naming standards are defined as a set of regular expression rules for artifact file names.

Figure 5 below shows a sample configuration of the wso2synapseStandards.json file.

Fig 5 - sample configurations of wso2synapseStandards.json file

(Fig 5: Sample configurations of wso2synapseStandards.json file)

How to use the plugin

To use this plugin, simply add the Synapse Validator Maven Plugin to your Maven project. In order to execute the plugin during the installation phase, we define the location of the WSO2 naming standards file (wso2namingStandards.json) which defines synapse validation rules for the artifacts, as well as the artifact.xml file of the composite application.

Figure 6 below, shows a sample of how to configure the Synapse Validator Maven Plugin in the Maven project’s <build> section.

Fig 6 - how to configure synapse-validator-maven-plugin in the maven project’s build section

(Fig 6: How to configure the Synapse Validator Maven Plugin in the Maven project’s section)

Ayeshmantha Perera

About the Author

Written by Ayeshmantha Perera – Associate Software Engineer at Mitra Innovation