Pick the xml field from the huge payload and remove square brackets.
Groovy Script:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.*;
import groovy.util.logging.*;
import org.codehaus.*;
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
map = message.getProperties();
requestid = map.get("ReqId");
taskid = map.get("TaskId");
requestid= requestid.toString().replaceAll("\\[", "");
requestid= requestid.toString().replaceAll('\\]', "");
def XmlDataObject = new XmlSlurper().parseText(body)
def xmldata = []
def s="";
XmlDataObject.'**'.findAll { it.name()== 'request_id'}.each { a ->
xmldata << a.text() }
def last = xmldata.last()
def xmldata2 = []
XmlDataObject.'**'.findAll { it.name()== 'task_id'}.each { a ->
xmldata2 << a.text() }
def last2 = xmldata2.last()
message.setProperty("requestid1",last);
def xmldata = []
def s="";
XmlDataObject.'**'.findAll { it.name()== 'request_id'}.each { a ->
xmldata << a.text() }
def last = xmldata.last()
def xmldata2 = []
XmlDataObject.'**'.findAll { it.name()== 'task_id'}.each { a ->
xmldata2 << a.text() }
def last2 = xmldata2.last()
message.setProperty("requestid1",last);
taskid= taskid.toString().replaceAll("\\[", "");
taskid= taskid.toString().replaceAll('\\]', "");
message.setProperty("taskid1",last2);
message.setProperty("taskid2",taskid);
return message;
}
taskid= taskid.toString().replaceAll('\\]', "");
message.setProperty("taskid1",last2);
message.setProperty("taskid2",taskid);
return message;
}
No comments:
Post a Comment