SoapUI获取模拟服务脚本中的请求参数 [英] SoapUI getting request parameters in mock service script
问题描述
在SoapUI模拟服务响应脚本中,如何提取我要回复的请求中的值?
假设传入请求包含
< ns1:foo>
< ns3:data>
< ns3:CustomerNumber> 1234< / ns3:CustomerNumber>
< / ns3:data>
< / ns1:foo>
如何将1234变为Groovy变量?我尝试了一个xmlHolder,但我似乎有错误的XPath。
(我知道如何设置一个属性并将它的值整合到响应中。)
如果您想要访问SOAP请求并执行一些XPath处理,那么在soapUI中有一种更简单的方法可以实现它, a href =http://groovy.codehaus.org/GPath =noreferrer> GPath 和 XmlSlurper 。
以下是您访问客户号码的方式:
def req = new XmlSlurper()。parseText(mockRequest.requestContent)
log.infoCustomer#$ {req.foo.data.CustomerNumber}
从Groovy 1.6.3(用于soapUI 2.5及更高版本)开始,XmlSlurper运行在名称空间感知默认情况下是非验证模式,所以没有其他你需要做的。
干杯!
Shonzilla
This is probably a very easy one for all SoapUI regulars.
In a SoapUI mock service response script, how do I extract the value inside the request I'm replying to?
Let's say the incoming request has
<ns1:foo>
<ns3:data>
<ns3:CustomerNumber>1234</ns3:CustomerNumber>
</ns3:data>
</ns1:foo>
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.)
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}"
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屋!