This documentation is for WSO2 Enterprise Service Bus version 4.8.0 . View documentation for the latest release.

All docs This doc

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Code Block
<definitions xmlns="">

        <sequence name="fault">
                <code value="tns:Receiver" xmlns:tns=""/>
                <reason value="Mediation failed."/>

        <sequence name="main" onError="fault">
                    <endpoint name="stockquote">
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                <class name="samples.mediators.SimpleClassMediator">
                    <property name="varible1variable1" value="10"/>
                    <property name="varible2variable2" value="5"/>


In this configuration, the ESB hands over the request message to the specified endpoint, which sends it to the Axis2 server running on port 9000. But the response message is passed through the Class Mediator before sending it back to the client. Two parameters named varible1 variable1 and varible2 variable2 are passed to the instance mediator implementation class (SimpleClassMediator). Look at the following sample Class Mediator and note the SynapseMessageContext and the full Synapse API in there.


Code Block
package samples.mediators;

    import org.apache.synapse.MessageContext;
    import org.apache.synapse.Mediator;
    import org.apache.axiom.soap.SOAPFactory;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    import javax.xml.namespace.QName;

    public class SimpleClassMediator implements Mediator {

        private static final Log log = LogFactory.getLog(SimpleClassMediator.class);

        private String varible1variable1="10";

        private String varible2variable2="10";

        private int varible3variable3=0;

        public SimpleClassMediator(){}

        public boolean mediate(MessageContext mc) {
            // Do somthing useful..
            // Note the access to the Synapse Message context
            return true;

        public String getType() {
            return null;

        public void setTraceState(int traceState) {
            traceState = 0;

        public int getTraceState() {
            return 0;

        public void setvarible1setVariable1(String newValue) {

        public String getvarible1getVariable1() {
            return varible1variable1;

        public void setvarible2setVariable2(String newValue){

        public String getvarible2getVariable2(){
            return varible2variable2;

For more examples, see Extending the Mediation in Java (Class Mediator).