在 SoapUI 模拟服务响应脚本中,我需要使用请求中的值

发布于 2024-10-09 20:44:04 字数 1602 浏览 0 评论 0原文

在 SoapUI 模拟服务响应脚本中,我需要使用请求中的值。我试图让 value_2 在响应中使用它。

例如,SOAPUI 模拟服务收到以下请求:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:ns1="urn:company:test">
   <SOAP-ENV:Body>
      <ns1:field_1 xmlns="urn:company:test">
         <field_2>
            <field_3>value_1</field_3>
         </field_2>
         <field_4>
            <field_5>
               <field_6>value_2</field_6>
            </field_5>
         </field_4>
          <field_4>
            <field_5>
               <field_6>value_3</field_6>
            </field_5>
         </field_4>
      </ns1:field_1>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我访问了以下链接,但它对我不起作用。

访问 SOAP UI 模拟响应中的请求 XML script

SoapUI 在模拟服务脚本中获取请求参数

我还尝试了以下几行但失败了。

def req = new XmlSlurper().parseText(mockRequest.requestContent)
context.theValue = req.field_1.field_4.field_5.field_6

另请注意,我使用的是基础版(不是专业版),

您能帮我解决这个问题吗?

谢谢,托尼

In a SoapUI mock service response script i need to use a value from a request. I am trying to get value_2 to use it in the response.

e.g. SOAPUI mock service receives the following request:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:ns1="urn:company:test">
   <SOAP-ENV:Body>
      <ns1:field_1 xmlns="urn:company:test">
         <field_2>
            <field_3>value_1</field_3>
         </field_2>
         <field_4>
            <field_5>
               <field_6>value_2</field_6>
            </field_5>
         </field_4>
          <field_4>
            <field_5>
               <field_6>value_3</field_6>
            </field_5>
         </field_4>
      </ns1:field_1>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I have visited the following links, but it did not work for me.

Access the request XML in a SOAP UI mock response script

SoapUI getting request parameters in mock service script

Also I tried following lines and failed.

def req = new XmlSlurper().parseText(mockRequest.requestContent)
context.theValue = req.field_1.field_4.field_5.field_6

Also please note that I use Basic Version (not Pro)

Could you please help me to resolve this issue?

Thanks, Tony

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落墨 2024-10-16 20:44:04

你可以尝试一下:

println req.Body.field_1.field_4*.field_5.field_6

应该打印出来吗

[value_2, value_3]

Can you try:

println req.Body.field_1.field_4*.field_5.field_6

That should print out

[value_2, value_3]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文