如何在SOAP UI中从SOAP请求中提取数据

时间:2015-02-13 11:23:20

标签: groovy soapui xmlslurper

我正在创建模拟SOAP响应,它应该返回SOAP-request中包含的数据。请找一个请求样本:

SOAP请求:

<v01:GetAncillaryOffersRQ version="1.0">
...
    <v01:PNRLocator itineraryRef="itinerary_1">AAAAAA</v01:PNRLocator>
...
</v01:GetAncillaryOffersRQ>

请找到应该返回的模拟响应:

模拟响应:

    <soapenv:Header></soapenv:Header>
   <soapenv:Body>
      <v01:GetAncillaryOffersRS version="?">
         <v021:ApplicationResults status="?">
            <v021:Error type="?" timeStamp="?">
               <v021:SystemSpecificResults timeStamp="?" reference="?">
                  <v021:Message code="?">No such PNR: ${pnrLocarotReq}</v021:Message>
                  <v021:DocURL>?</v021:DocURL>
               </v021:SystemSpecificResults>
            </v021:Error>           
         </v021:ApplicationResults>
      </v01:GetAncillaryOffersRS>
   </soapenv:Body>

我正在尝试使用以下脚本将值从SOAP请求传递到模拟响应:

def req = new XmlSlurper().parseText(mockRequest.requestContent)
def pnrLocarotReq = req.GetAncillaryOffersRQ.PNRLocator
log.info "PNR Locator: $pnrLocarotReq"

此值不会传递给响应。从我在控制台中可以看到,参数值不是从请求中提取的。

控制台输出:

Fri Feb 13 12:22:23 CET 2015:INFO:PNR Locator: 

你能告诉我我做错了吗?

1 个答案:

答案 0 :(得分:0)

这段代码对我来说很好:

def req = new XmlSlurper().parseText(mockRequest.requestContent)
def pnrLocarotReq = req.Body.GetAncillaryOffersRQ.PNRLocator
log.info "PNR Locator: $pnrLocarotReq"

非常感谢userRao