我正在使用SOAP UI 3.0.1来测试我的Web服务,它返回一个字节数组。我想将字节数组保存为word文件。如何使用Groovy Script或任何其他方式完成它? Web服务响应是, 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7 / CQAGAAAAAAA ...............................
答案 0 :(得分:3)
宾果!!
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)