Skip to content

Instantly share code, notes, and snippets.

@ssisaias
Last active April 18, 2019 16:57
Show Gist options
  • Save ssisaias/00ae2a3b669890e9ba04c50aa2bd643f to your computer and use it in GitHub Desktop.
Save ssisaias/00ae2a3b669890e9ba04c50aa2bd643f to your computer and use it in GitHub Desktop.
Remove tag from payload using WSO2 axiom engine and custom mediators
public boolean mediate(MessageContext context) {
try {
String test = context.getProperty("mock_property").toString();
OMElement xmlPayload = AXIOMUtil.stringToOM(test);
//log.info(xmlPayload);
OMElement envelope = context.getEnvelope().getBody().getFirstElement();
//log.info(envelope);
OMElement body = envelope.getFirstElement();
//log.info(body);
OMElement items = body.getFirstElement();
//log.info(items);
OMElement item = items.getFirstElement();
//log.info(item);
Iterator _details = item.getChildren();
while(_details.hasNext()){
Object detail = _details.next();
if(detail instanceof OMElement) {
OMElement omElement = (OMElement)detail;
String elementName = omElement.getLocalName();
log.info(elementName);
if ("elementToRemove".equals(elementName)) {
omElement.detach();
break;
}
}
}
log.info(envelope);
return true;
}
catch(XMLStreamException e) {
log.error(e);
return false;
}
catch(Exception e){
log.error(e);
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment