Enterprise Integration Zone is brought to you in partnership with:

I am a graduate of University of Westminster UK (IIT) B Sc Software Engineering ( First Class Honours). I am a Sun Certified Java Programmer for Java 2 platform, 1.5 versions (SCJP 1.5). – 93% and a Sun Certified Web Component Developer 97%. I work as a Software Engineer at WSO2. Achala is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

How to write a custom dispatcher for WSO2 ESB

02.01.2013
| 2083 views |
  • submit to reddit
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"/>

Published at DZone with permission of Achala Chathuranga Aponso, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)