How to export pdf attachment from soap response using groovy?

╄→尐↘猪︶ㄣ 提交于 2020-01-03 05:40:21

问题


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 ?


回答1:


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

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

Source for the script is taken from 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()


来源:https://stackoverflow.com/questions/39619511/how-to-export-pdf-attachment-from-soap-response-using-groovy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!