如何使用Groovy从Soap响应中导出pdf附件? [英] How to export pdf attachment from soap response using groovy?

查看:187
本文介绍了如何使用Groovy从Soap响应中导出pdf附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管 soap (肥皂)(免费版)具有导出响应生成的文档的选项.有什么俗套的功能可以提取应用程序/pdf文件并将其存储在我的本地文件夹中吗?

Although soap (free version) has an option to export document generated in response. Is there any groovy function to extract application/pdf file and store in my local folder ?

推荐答案

以下脚本应该能够将附件保存到文件中.

The following script should be able to save the attachment to a file.

将以下脚本作为Script Assertion添加到当前请求步骤.内联找到适当的注释.

Add the below script as Script Assertion to the current request step. Find the appropriate comments inline.

该脚本的来源来自此处

/**
* 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()

这篇关于如何使用Groovy从Soap响应中导出pdf附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆