Search code examples
wso2esbwso2-enterprise-integratorapache-synapsewso2-esb

WSO2 EI, How to get payload as String from Custom Class mediator


I have created my own MediatorClass. Which has this major method:

public boolean mediate(MessageContext context) { 
    // TODO Implement your mediation logic here
    return true;
}

Now there is a problem. This mediator is part of REST API sequence which has Text body that I want to edit.

How it's possible to extract this Payload as String?


Solution

  • Get the root element of the soap body :

    OMElement element = (OMElement) context.getEnvelope().getBody().getFirstOMChild();
    

    (see MessageContext)

    Just use element.toString() (see OMElement)