Eğer aşağıdaki gibi hata içerikli bir xml mesajında, sadece hata koşulunda değişiklik yapmak istenirse XmlSlurper Groovy ile kullanılabilir.
Örnek mesaj:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>
soap:Server
</faultcode>
<faultstring>
javax.xml.ws.WebServiceException: com.exception.BaseUserException: Some Error.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
XML
Groovy İfadesi:
import groovy.xml.XmlSlurper
import groovy.xml.XmlUtil
var rootNode = new XmlSlurper(false, true).parseText(responseBodyTextFromTargetAPI).declareNamespace('soap':'http://schemas.xmlsoap.org/soap/envelope/')
def element=rootNode.'soap:Body'.'soap:Fault'.'faultstring'
if(element != ''){
rootNode.'soap:Body'.'soap:Fault'.replaceNode { }
rootNode.'soap:Body'.appendNode {
faultstring(element.text())
}
responseBodyTextFromTargetAPI = XmlUtil.serialize(rootNode)
}
GROOVY
Sonuç:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<faultstring>
javax.xml.ws.WebServiceException: com.exception.BaseUserException: Some Error.
</faultstring>
</soap:Body>
</soap:Envelope>
XML