Last active
May 10, 2019 03:49
-
-
Save athiththan11/71e8c5baa662c34b46a008ea824332a9 to your computer and use it in GitHub Desktop.
WSO2 Class Mediator implementation to manipulate and convert payloads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package <your package namespace>; | |
import org.apache.synapse.MessageContext; | |
import org.apache.synapse.commons.json.JsonUtil; | |
import org.apache.synapse.core.axis2.Axis2MessageContext; | |
import org.apache.synapse.mediators.AbstractMediator; | |
import org.json.JSONObject; | |
public class CustomMediator extends AbstractMediator { | |
@Override | |
public boolean mediate(MessageContext synCtx) { | |
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx) | |
.getAxis2MessageContext(); | |
try { | |
JSONObject jsonObject = new JSONObject(JsonUtil.jsonPayloadToString(axis2MessageContext)); | |
if (jsonObject.has("dev") && jsonObject.getJSONObject("dev").has("name") | |
&& "medium".equals((String) jsonObject.getJSONObject("dev").get("name"))) { | |
jsonObject.getJSONObject("dev").put("name", "Athiththan"); | |
} | |
JsonUtil.newJsonPayload(axis2MessageContext, jsonObject.toString(), true, true); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment