2

I am using SOAP UI 3.0.1 for testing my web service which returns a byte array. I want to save the byte array as a word file. How do I accomplish it using Groovy Script or any other way? The web service response is, 0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAA...............................

1 Answer 1

3

Bingo!!

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.