Copying values from SOAP UI request into SOAP UI response using groovy

I am trying to copy some values from SOAP request XML into SOAP response XML file.

Consider following request and response XML for reference:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ehit="http://www.calheers.ca.gov/EHITSAWSInterfaceMessageSchema" xmlns:ehit1="http://www.calheers.ca.gov/EHITSAWSInterfaceCommonSchema" xmlns:ns="http://niem.gov/niem/structures/2.0" xmlns:ns2="http://niem.gov/niem/niem-core/2.0" xmlns:ns1="http://niem.gov/niem/domains/screening/2.1">
  <soapenv:Header/>
  <soapenv:Body>
  <ehit:DeterminationRequest>
     <ehit:MessageInformation>
        <ehit1:MessageID ns:id="?" ns:metadata="?" ns:linkMetadata="?">?   </ehit1:MessageID>
        <ehit1:MessageTimeStamp ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:MessageTimeStamp>
        <ehit1:SendingSystem ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:SendingSystem>
        <ehit1:ReceivingSystem ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:ReceivingSystem>
        <ehit1:FipsCountyCode ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:FipsCountyCode>
        <!--Optional:-->
        <ehit1:TracerID ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:TracerID>
     </ehit:MessageInformation>
     .......continued......

And Response XML is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ehit="http://www.calheers.ca.gov/EHITSAWSInterfaceMessageSchema" xmlns:ehit1="http://www.calheers.ca.gov/EHITSAWSInterfaceCommonSchema" xmlns:ns="http://niem.gov/niem/structures/2.0">
<soapenv:Header/>
<soapenv:Body>
  <ehit:DeterminationResponse>
     <ehit1:MessageID ns:id=${id} ns:metadata=${metadata} ns:linkMetadata="?">?</ehit1:MessageID>
     <ehit1:AckTimeStamp ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:AckTimeStamp>
     <!--Optional:-->
     <ehit1:StatusCode ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:StatusCode>
     <!--Optional:-->
     <ehit1:ErrorCode ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:ErrorCode>
     <!--Optional:-->
     <ehit1:ErrorMessage ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:ErrorMessage>
  </ehit:DeterminationResponse>
</soapenv:Body>
</soapenv:Envelope>

I created two dynamic vars here ${id} and ${metadata}.

I tried to copy id and metadata attribute of .Now to set these values from request into response I am using following script:

def req = new XmlSlurper().parseText(mockRequest.requestContent)
requestContext.id = req.Body.DeterminationRequest.MessageInformation.MessageID.@id;
requestContext.metadata = req.Body.DeterminationRequest.MessageInformation.MessageID.@metadata;

But it’s not returning any value. Can someone help me to figure it out what I am doing wrong here?

Also if I want to copy many (consider 50+) values from request into response then is there any simple way instead of creating 50+ variables? Because in my case I have to copy all values from request into response message.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s