How to Add new Namespace to SOAP Envelope

There are some points you may face instead of keeping the body content’s namespace in the SOAP envelope, in such scenarios you can use Enrich Mediator to get this done.

Add the following enrich mediators three times and add new namespace to envelope where ever you want. And then use the new namespace inside a payload factory mediator.

      <source type="body" />
      <target type="property" property="ORG_BODY" />
      <source type="inline">
         <soapenv:Envelope xmlns:soapenv="" xmlns:newns="">
            <soapenv:Body />
      <target type="envelope" />
      <source type="property" property="ORG_BODY" />
      <target type="body" />
      <!--we have to define the new namespace here too but it doesn't appear in the new body since it's already defined in the envelope tag -->
      <newns:bodycontent xmlsns:newns="">.....</newns:bodycontent>

Invoking WSO2 ESB Proxy Service from Scheduled Task

Following java class invoke the given proxy (proxy name should be given as the parameter) and the inbuilt message body is send to the specified proxy service.

NOTE: Following sample is scheduled task implementation class in WSO2 ESB. Continue reading

Usage of a Respond Mediator in WSO2 ESB

In a situation like you want to send a message back to the client depending on some conditions, we can use Respond Mediator. This mediator stops the processing on the current message and sends the message back to the client as a response. So just before this mediator we can use mediator like Payload Factory Mediator to construct the response.

Following is a simple use case for this,

Continue reading

How to move to out sequence from in sequence in WSO2 ESB

I faced a situation, where I need to send a custom response after the request is being sent to the message queue. I couldn’t use FORCE_SC_ACCEPT property as I need to send a response. In such a case we can use loopback mediator which switch from in sequence to out sequence and in side the out sequence payload factory mediator can be used to construct the custom response.

Simple skeleton as follows,

Continue reading

JSON Support for WSO2 ESB Class Mediator

In WSO2 documentation you can find how the following mediators can be used with json payloads.

  • Log Mediator
  • Property Mediator
  • PayloadFactory Mediator
  • Switch Mediator
  • Filter Mediator

But there’s no any clue about how the class mediator can be used with json payloads. Following is the way you can do manipulation to json payload using class mediator.

In this post I just add a new tag to existing json payload

package com.wso2.test;

import org.apache.synapse.MessageContext;
import org.apache.synapse.commons.json.JsonUtil;
import org.json.JSONObject;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

* Class mediator for JSON transformation.
* @author isuru
public class JSONClassMediator extends AbstractMediator {

* Holds the name.
private String nameParam;

* Mediate overridden method to set the token property.
public boolean mediate(MessageContext context) {

try {

// Getting the json payload to string
String jsonPayloadToString = JsonUtil
.jsonPayloadToString(((Axis2MessageContext) context)
// Make a json object
JSONObject jsonBody = new JSONObject(jsonPayloadToString);

// Adding the name:nameParam.
jsonBody.put("name", getNameParam());

String transformedJson = jsonBody.toString();

// Setting the new json payload.
((Axis2MessageContext) context).getAxis2MessageContext(),
transformedJson, true, true);

System.out.println("Transformed JSON body:\n" + transformedJson);

} catch (Exception e) {
System.err.println("Error occurred: " + e);
return false;

return true;

* @return the nameParam
public final String getNameParam() {
return nameParam;

* @param nameParam
* the nameParam to set
public final void setNameParam(String nameParam) {
this.nameParam = nameParam;

Continue reading

Usage of Fault mediator in WSO2 ESB

This post explains, an usage of Fault mediator in wso2 ESB.

The sample scenario, refuses and sends an exception back to the client based on the Content-Type header property.

This example is tested in ESB 4.7.0

First validate the content-type - using filter mediator

If true, send back an exception to the client - using fault mediator

If false, continue the flow

Here is the sample proxy,

Continue reading

How to send an Email using WSO2 ESB

This post explains how to send an email in WSO2 ESB using Payload Factory mediator . You can find plenty of examples which do the same by using Script mediator.

This example is tested in WSO2 ESB 4.8

1.Uncomment and configure the SMTP server information ESB_HOME/repository/conf/axis/axis2.xml file as below

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
   <parameter name=""></parameter>
   <parameter name="mail.smtp.port">587</parameter>
   <parameter name="mail.smtp.starttls.enable">true</parameter>
   <parameter name="mail.smtp.auth">true</parameter>
   <parameter name="mail.smtp.user">esbadmin</parameter>
   <parameter name="mail.smtp.password">*****</parameter>
   <parameter name="mail.smtp.from"></parameter>

Continue reading