Java 如何从soapui保存压缩响应?

Java 如何从soapui保存压缩响应?,java,http,soap,gzip,soapui,Java,Http,Soap,Gzip,Soapui,这是来自soapui的明确响应内容。但在我的例子中,响应内容是使用gzip格式保存的,因此文件内容应该“解压缩”以便阅读。是否可以在保存期间解压缩soapui中的响应?我认为不可能直接使用soapui选项。但是,您可以使用groovy脚本来完成 在testStep请求之后添加groovy testStep,该请求将响应保存到转储文件中。在这个groovy测试步骤中添加以下代码,解压您的响应并将结果保存在Dump文件的同一路径中,您只需指定Dump文件名称和目录,以便groovy脚本可以解压它:

这是来自soapui的明确响应内容。但在我的例子中,响应内容是使用gzip格式保存的,因此文件内容应该“解压缩”以便阅读。是否可以在保存期间解压缩soapui中的响应?

我认为不可能直接使用
soapui
选项。但是,您可以使用groovy脚本来完成

testStep
请求之后添加
groovy testStep
,该请求将响应保存到
转储文件中。在这个
groovy测试步骤中
添加以下代码,解压您的响应并将结果保存在
Dump文件
的同一路径中,您只需指定
Dump文件
名称和目录,以便
groovy
脚本可以解压它:

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()
我再次阅读了您的问题,我意识到您想要解压缩no-unzip,因此您可以使用以下groovy代码:

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();
希望这有帮助