SoapUI 在模拟服务脚本中获取请求参数 [英] SoapUI getting request parameters in mock service script

查看:37
本文介绍了SoapUI 在模拟服务脚本中获取请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于所有 SoapUI 常客来说,这可能是一个非常简单的方法.

This is probably a very easy one for all SoapUI regulars.

在 SoapUI 模拟服务响应脚本中,如何提取我正在回复的请求中的值?

In a SoapUI mock service response script, how do I extract the value inside the request I'm replying to?

假设传入的请求有

<ns1:foo>
  <ns3:data>
    <ns3:CustomerNumber>1234</ns3:CustomerNumber>
  </ns3:data>
</ns1:foo>

如何将1234"放入 Groovy 变量中?我尝试使用 xmlHolder,但 XPath 似乎有误.

How do I get the "1234" into a Groovy variable? I tried with an xmlHolder but I seem to have the wrong XPath.

(我已经知道如何设置属性并将其值集成到响应中.)

(I know how to set a property and integrate its value into the response already.)

推荐答案

如果您想访问 SOAP 请求并进行一些 XPath 处理,由于 GPathXmlSlurper.

If you want to access SOAP request and do some XPath processing, there's an easier way to do it in soapUI thanks to the power of GPath and XmlSlurper.

您可以通过以下方式访问客户编号:

Here's how you would access the customer number:

def req = new XmlSlurper().parseText(mockRequest.requestContent)
log.info "Customer #${req.foo.data.CustomerNumber}"

从 Groovy 1.6.3(在 soapUI 2.5 及更高版本中使用)开始,XmlSlurper 默认在命名空间感知和非验证模式下运行,因此您无需执行其他任何操作.

As of Groovy 1.6.3 (which is used in soapUI 2.5 and beyond), XmlSlurper runs in namespace-aware and non-validating mode by default so there's nothing else you need to do.

干杯!
松兹拉

Cheers!
Shonzilla

这篇关于SoapUI 在模拟服务脚本中获取请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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