Saturday, July 28, 2012

How to write a custom dispatcher for WSO2 ESB

Create a maven project and add 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 in to 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"/>


No comments:

Post a Comment

Using Zotero for academic writing