Monday, March 27, 2017

How to use the custom Axis2 handler in WSO2 ESB

In this article, I'm going to explain how to use Axis2 handler in WSO2 ESB

1. Implement a sample Synapse handler. You can follow my previous blog to write a Synapse handler

2. Implement a sample module

package com.wso2.handler.sample;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisDescription;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.modules.Module;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;

/**
 * Created by tharanga.
 */
public class SampleAxis2Module implements Module {
    public void init(ConfigurationContext configurationContext, AxisModule axisModule) throws AxisFault {
        System.out.println("==================================================");
    }

    public void engageNotify(AxisDescription axisDescription) throws AxisFault {

    }

    public boolean canSupportAssertion(Assertion assertion) {
        return true;
    }

    public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {

    }

    public void shutdown(ConfigurationContext configurationContext) throws AxisFault {

    }
}

3. Created module.xml as below (in resources folder /META-INF/module.xm)


<module name="CustomLoggingModule" class="com.wso2.handler.sample.SampleAxis2Module">
    <InFlow>
        <handler name="InFlowLogHandler" class="com.wso2.handler.sample.SampleAxis2Handler">
            <order phase="CustomLoggingModulePhase" />
        </handler>
    </InFlow>
</module>

4. Build the jar file and rename to mar and put it into the ESB_HOME/repository/deployment/server/axis2modules/ folder

5. Added the module to the axis2.xml as below
<module ref="CustomLoggingModule"/>

6. To test the scenario I added the phase to the InFlow as below

<phaseOrder type="InFlow">
    ....
    ....
    <phase name="CustomLoggingModulePhase"/>
 </phaseOrder>

7. Start the ESB

No comments:

Post a Comment