Over a million developers have joined DZone.

How to write a custom dispatcher for WSO2 ESB

Build APIs from SQL and NoSQL data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.

Create a maven project and add the following dependencies to the pom.xml
<?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>
    <groupId>Custom_Dispatcher</groupId>
    <artifactId>CustomDispatcher</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.synapse</groupId>
            <artifactId>synapse-core</artifactId>
            <version>2.1.0-wso2v5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.synapse</groupId>
            <artifactId>synapse-extensions</artifactId>
            <version>2.1.0-wso2v5</version>
        </dependency>
    </dependencies>
</project>
The new dispatcher will be 'CustomDispatcher'.

Write your own dispatcher (Get an idea about the CustomURIBasedDispatcher.java )
https://svn.wso2.com/wso2/custom/projects/projects/carbon/3.2.3/trunk/dependencies/synapse/2.1.0-wso2v5/modules/core/src/main/java/org/apache/synapse/core/axis2/CustomURIBasedDispatcher.java

Copy it to [WSO2_ESB_Installation]/repository/components/lib and restart ESB.

Include the following in the axis2.xml. It should be inserted into the dispatch phase of the In-Flow of the ESB. It should be the first handler in the Dispatch phase.
<handler name="CustomDispatcher"
 class="com.wso2.Dispatcher.CustomDispatcher"/>

The Integration Zone is brought to you in partnership with CA Technologies.  Create app backends instantly with REST APIs and reactive logic using CA Live API Creator.

Topics:

Published at DZone with permission of Achala Chathuranga Aponso , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}