Monday, January 7, 2013

Writing a Custom Mediator for WSO2 ESB - Part 3

This is the last part of blog post series about creating a WSO2 ESB mediator. Older parts are,
  1. Part 1
  2. Part 2
In this post I will explain the UI component of a ESB mediator using the BAM mediator (Carbon version 4.0.5). UI component (i.e.: org.wso2.carbon.mediator.bam.ui) is responsible for the BAM mediator specific UIs in the following UI.

Mediator UI

When BAM mediator is selected in the above mediator sequence (there is only the BAM mediator is available here anyway) the UI located under the sequence UI, is specified in the mediator UI component. Anyway not all the UI under it comes from the UI component. UI between the bar named Mediator and Update button comes from the UI component. Actually this is the edit-mediator.jsp JSP located in the resources package in org.wso2.carbon.mediator.bam.ui component.
After the changes are made on UI the user can click on the above mentioned Update button. This event will call the update-mediator.jsp JSP adjacent to the edit-mediator.jsp JSP.

When switch to source view is clicked the following source appears.

And you can return back to design view by clicking on switch to design view link. This toggling mechanism need the implementation of UI component. In simple terms this functionality need the implementation of,
  1. BamMediator UI class - similar to BamMediator class in backend component
  2. serialize method - similar to serializeSpecificMediator method in BamMediatorSerializer class in backend component
  3. build method - similar to createSpecificMediator method in BamMediatorFactory class in backend component

Abstract Mediator Class (UI)

The difference of UI component with backend component is, that both serialize method and build method are included in the BamMediator UI class. BamMediator UI class can be found in org.wso2.carbon.mediator.bam.ui package.
BamMediator class should inherit from org.wso2.carbon.mediator.service.ui.AbstractMediator.
And also it should implement getTagLocalName method, similar to getTagQName used in backend. And also the serialize and build methods as mentioned earlier should be implemented.

public class BamMediator extends AbstractMediator {

    public String getTagLocalName() {


    public OMElement serialize(OMElement parent) {


    public void build(OMElement omElement) {



Abstract Mediator Service Class

Every mediator UI component should consists of a Mediator Service class. In this example BamMediatorService is the class which implements the required settings of the UI. Let's explain with the example.

public class BamMediatorService extends AbstractMediatorService {

    public String getTagLocalName() {
        return "bam";

    public String getDisplayName() {
        return "BAM";

    public String getLogicalName() {
        return "BamMediator";

    public String getGroupName() {
        return "Agent";

    public Mediator getMediator() {
        return new BamMediator();


As the example says every Mediator Service should inherit the org.wso2.carbon.mediator.service.AbstractMediatorService class.
Note how the name BAM is used as the sequence editor under the sub menu item named Agent. See how the getMediator method is used to execute the BamMediator UI class which we have discussed earlier.

Bundle Activator Class

Unlike other Carbon bundles where Bundle Activator is defined in the backend bundle, in a mediator class, the Bundle Activator is defined in the  UI bundle. In this example it is BamMediatorActivator class.

Basically the Bundle Activator should inherit the org.osgi.framework.BundleActivator class and should implement start and stop methods. For further information read this article.

Properties props = new Properties();

bundleContext.registerService(MediatorService.class.getName(), new BamMediatorService(), props);

Note how the BamMediatorService class is used.

Congratulations, you have finished the post series of how to write a custom mediator with WSO2 ESB. If you could not understand this well, most probably that is because you are not familiar with WSO2 Carbon platform. If you search more you will be able to catch them.


  1. hi this is murali. can u please tell me about wso2 and why it is used?. i am just new to the web services. will u please elaborate the details.
    thanks in advance

  2. @Murali,

    WSO2 is an Free and Open Source (Apache License 2.0) software company. It is said that WSO2 is the only open source product stack supports all web service use cases. At the beginning of WSO2 it was almost focused on web service based middleware. But now it has a variety of products supporting different kinds of enterprise middleware requirements.

    All software from WSO2 are free and open source. WSO2 earn by supporting development services, development support and production support. You too can download software free from the site and try them. :-)

  3. Custom Software Development Delhi that mitigate risks, enhance productivity, channelize work flow, and provide early corrective solutions to your problems.