2
我正在使用SOAP UI 3.0.1來測試返回字節數組的Web服務。我想將字節數組保存爲一個字文件。我如何使用Groovy Script或其他方式實現它? web服務響應是, 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAA ............................... 如何使用SOAP UI將Web服務響應(字節數組)作爲文件保存?
我正在使用SOAP UI 3.0.1來測試返回字節數組的Web服務。我想將字節數組保存爲一個字文件。我如何使用Groovy Script或其他方式實現它? web服務響應是, 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAA ............................... 如何使用SOAP UI將Web服務響應(字節數組)作爲文件保存?
賓果!
import org.apache.commons.codec.binary.Base64
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
filename = groovyUtils.projectPath + "\\" +System.currentTimeMillis()+ ".doc"
def objFile = new java.io.File(filename)
def holder = groovyUtils.getXmlHolder('GetDocument#Response');
holder.declareNamespace('ns1','Utlities.Service.Documents');
def byteArray = holder.getNodeValue("//ns1:GetDocumentResponse[1]/ns1:GetDocumentResult")
def b64 = new Base64()
def textBytes = b64.decode(byteArray.getBytes())
FileOutputStream fos = new java.io.FileOutputStream(objFile);
fos.write(textBytes);
fos.flush();
fos.close();
log.info("Output file: " + filename)