Cherry
Cherry

Reputation: 33504

How save compressed response from soapui?

It is clear how to save response content from soapui. But in my case response content saved using gzip format, so the file content should be "ungzipped" for reading. Is it possible to uncompresss response in soapui during saving?

Upvotes: 2

Views: 1492

Answers (1)

albciff
albciff

Reputation: 18507

I think it's not possible doing it directly with SOAPUI options. However you can do it with a groovy script.

Add a groovy testStep following the testStep Request which saves your response to a Dump File. In this groovy testStep add the follow code which unzip your response and save the result in the same path the your Dump File, you've only to specify the Dump File name and directory in order the groovy script can unzip it:

import java.io.ByteArrayInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream

def buffer = new byte[1024]

// create the zip input stream from your dump file
def dumpFilePath = "C:/dumpPath/"
FileInputStream fis = new FileInputStream(dumpFilePath + "dumpFile.zip")
def zis = new ZipInputStream(fis)
def zip = null

// get each entry on the zip file
while ((zip = zis.getNextEntry()) != null) {

    // decompile each entry
    log.info("Unzip entry here: " + dumpFilePath + zip.getName())
    // create the file output stream to write the unziped content
    def fos = new FileOutputStream(dumpFilePath + zip.getName())
    // read the data and write it in the output stream
    int len;
     while ((len = zis.read(buffer)) > 0) {
        fos.write(buffer, 0, len)
     }

    // close the output stream
    fos.close();
    // close entry
    zis.closeEntry()
}

// close the zip input stream
zis.close()

I read again your question and I realize that you want to ungzip no unzip so maybe you can use this groovy code instead:

import java.io.ByteArrayInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.util.zip.GZIPInputStream

def buffer = new byte[1024]

// create the zip input stream from your dump file
def dumpFilePath = "C:/dumpPath/"
FileInputStream fis = new FileInputStream(dumpFilePath + "dumpFile.gz")
// create the instance to ungzip
def gzis = new GZIPInputStream(fis)
// fileOutputStream for the result
def fos = new FileOutputStream(dumpFilePath + "ungzip")
// decompress content
gzis.eachByte(1024){ buf, len -> fos.write(buf,0,len)}
// close streams
gzis.close();
fos.close();

Hope this helps,

Upvotes: 1

Related Questions