Search code examples
groovysoapuixmlslurper

How to extract data from SOAP-request in SOAP UI


I'm creating mock SOAP-response which should return data contained in SOAP-request. Please, find a request sample:

SOAP-Request:

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

Please, find mock-response which should be returned:

Mock Response:

    <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>

And I'm trying to pass value from SOAP-request to mock responce with the following script:

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

And this value isn't passed to response. And from that I can see in console, parameter value isn't extracted from request.

Console Output:

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

Could you tell me what I'm doing wrong?


Solution

  • This code worked fine for me:

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

    Many thanks to userRao