gpt4 book ai didi

java - 如何保存 soapui 的压缩响应?

转载 作者:可可西里 更新时间:2023-11-01 16:37:40 26 4
gpt4 key购买 nike

很清楚how to save来自soapui的回复内容。但在我的例子中,响应内容使用 gzip 格式保存,因此文件内容应该被“解压缩”以供阅读。是否可以在保存期间在 soapui 中解压缩响应?

最佳答案

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

testStep 请求之后添加一个 groovy testStep 将您的响应保存到 Dump File。在此 groovy testStep 中添加以下代码,解压缩您的响应并将结果保存在与您的 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()

我再次阅读了你的问题,我意识到你想解压缩而不是解压缩,所以也许你可以改用这个常规代码:

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();

希望对您有所帮助,

关于java - 如何保存 soapui 的压缩响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27978651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com