如何从soapUI响应中提取字节数组?
我正在使用soapUI 测试网络服务。 其中一个响应如下所示:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getInputConfigFilesResponse xmlns:ns2="http://ws.pdb.ericsson.se/">
<return>UEsDBBQACAAIAO1GNToAAAAAAAAAAAAAAAANAAAAc2NyaXB0cy9lbGxza [...] AATAAAAAAAAAAAAAAAAAAGXAAAbGRhcF9ub2RlX2NvbmZpZ3VyYXRpb24vZ2VuZXJhdGVkX2xkaWZfZmlsZXMvX210YXM0X2N4cDQ0NF9yNF9JbXNtb2JpbGUubGRpZlBLAQIUABQACAAIAO1GNTp8eBuZRAEAABMDAAAmAAAAAAAAAAAAAAAAAKJiAABsZGFwX25vZGVfY29uZmlndXJhdGlvbi9lbGxzaC1jb21tYW5kc1BLBQYAAAAABQAFAIgBAAA6ZAAAAAA=</return>
</ns2:getInputConfigFilesResponse>
</S:Body>
</S:Envelope>
响应是一个字节数组,应表示一个 zip 文件。 我该如何去验证这一点?
I am testing a web service with soapUI. One of the responses looks like this:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getInputConfigFilesResponse xmlns:ns2="http://ws.pdb.ericsson.se/">
<return>UEsDBBQACAAIAO1GNToAAAAAAAAAAAAAAAANAAAAc2NyaXB0cy9lbGxza [...] AATAAAAAAAAAAAAAAAAAAGXAAAbGRhcF9ub2RlX2NvbmZpZ3VyYXRpb24vZ2VuZXJhdGVkX2xkaWZfZmlsZXMvX210YXM0X2N4cDQ0NF9yNF9JbXNtb2JpbGUubGRpZlBLAQIUABQACAAIAO1GNTp8eBuZRAEAABMDAAAmAAAAAAAAAAAAAAAAAKJiAABsZGFwX25vZGVfY29uZmlndXJhdGlvbi9lbGxzaC1jb21tYW5kc1BLBQYAAAAABQAFAIgBAAA6ZAAAAAA=</return>
</ns2:getInputConfigFilesResponse>
</S:Body>
</S:Envelope>
The response is a byte array which should represent a zip file. How can I go about verifying this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管在语义上是正确的,但我认为内森提出的解决方案有些不完整。
我猜他忘记在步骤 1 之前对提取的文本进行 Base64 解码。我还将进行一项改进,以便通过使用第 3 方 ZIP 实用程序验证临时文件而无需人工干预。
这将转化为访问临时 ZIP 文件并检查它是否是有效的 ZIP 文件。 因此,实现您的要求的算法是:
内容并进行 Base64 解码 将
考虑到所有这些,完整的 Groovy 脚本如下所示:
请告诉我是否这样对你有用,对我也有用。 :-)
干杯!
尚齐
拉 我建议在这个问题中添加“ZIP”标签,以便人们可以更轻松地找到处理此处嵌入的 Groovy 中的 ZIP 的解决方案。
Although semantically correct, I believe Nathan's proposed solution is somewhat incomplete.
I guess he forgot do Base64 decode the extracted text prior to step 1. I would also include an improvement so that no human intervention is needed by verifying the temporary file using 3rd party ZIP utilities.
That would translate into accessing the temporary ZIP file and checking whether it's a valid ZIP file. Therefore, an algorithm for implementing your requirement would be:
content and Base64 decode it
With all that in mind, here's how the complete Groovy script would look like:
Please let me know if this works for you as it does for me. :-)
Cheers!
Shonzilla
p.s. I would suggest adding "ZIP" tag to this question so that people can more easily find a solution for handling ZIPs from Groovy that's embedded here.
你将不得不使用一些groovy。
编辑:添加了一些示例代码。
def saveFile = new java.io.File(saveTestDir + "\\testreturn.zip")
FileOutputStream fos = new java.io.FileOutputStream(saveFile);
def zipBytes = context.expand( '${Step#Request#//ns2:getInputConfigFilesResponse[1]/return[1]}' );
fos.write( zipBytes.getBytes() );< /code>
fos.flush();
fos.close();
You're going to have to use some groovy.
Edit: added some sample code.
def saveFile = new java.io.File(saveTestDir + "\\testreturn.zip")
FileOutputStream fos = new java.io.FileOutputStream(saveFile);
def zipBytes = context.expand( '${Step#Request#//ns2:getInputConfigFilesResponse[1]/return[1]}' );
fos.write( zipBytes.getBytes() );
fos.flush();
fos.close();