如何使用 groovy 从 soap 响应中导出 pdf 附件?
How to export pdf attachment from soap response using groovy?
尽管 soap(免费版)有一个选项可以导出响应中生成的文档。是否有任何 groovy 函数可以提取 application/pdf 文件并存储在我的本地文件夹中?
以下脚本应该能够将附件保存到文件中。
将以下脚本作为 Script Assertion
添加到当前请求步骤。查找内联的适当评论。
脚本源取自here
/**
* Below script assertion will check
* if the response is not null
* there is an attachment
* and saves file to the specified location, by default saves into system temp
* directory
**/
//change file name as needed
def fileName = System.getProperty('java.io.tmpdir')+'/test.pdf'
//Get the response and check if the response is not null
def response = messageExchange.response
assert null != response, "response is null"
//Create output stream
def outFile = new FileOutputStream(new File(fileName))
//Check if there is one attachment in the response
assert 1 == messageExchange.responseAttachments.length, "Response attachments count not matching"
def ins = messageExchange.responseAttachments[0]?.inputStream
if (ins) {
//Save to file
com.eviware.soapui.support.Tools.writeAll( outFile, ins )
}
ins.close()
outFile.close()
尽管 soap(免费版)有一个选项可以导出响应中生成的文档。是否有任何 groovy 函数可以提取 application/pdf 文件并存储在我的本地文件夹中?
以下脚本应该能够将附件保存到文件中。
将以下脚本作为 Script Assertion
添加到当前请求步骤。查找内联的适当评论。
脚本源取自here
/**
* Below script assertion will check
* if the response is not null
* there is an attachment
* and saves file to the specified location, by default saves into system temp
* directory
**/
//change file name as needed
def fileName = System.getProperty('java.io.tmpdir')+'/test.pdf'
//Get the response and check if the response is not null
def response = messageExchange.response
assert null != response, "response is null"
//Create output stream
def outFile = new FileOutputStream(new File(fileName))
//Check if there is one attachment in the response
assert 1 == messageExchange.responseAttachments.length, "Response attachments count not matching"
def ins = messageExchange.responseAttachments[0]?.inputStream
if (ins) {
//Save to file
com.eviware.soapui.support.Tools.writeAll( outFile, ins )
}
ins.close()
outFile.close()