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="" xmlns:ehit="" xmlns:ehit1="" xmlns:ns="" xmlns:ns2="" xmlns:ns1="">
        <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>
        <ehit1:TracerID ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:TracerID>

And Response XML is:

<soapenv:Envelope xmlns:soapenv="" xmlns:ehit="" xmlns:ehit1="" xmlns:ns="">
     <ehit1:MessageID ns:id=${id} ns:metadata=${metadata} ns:linkMetadata="?">?</ehit1:MessageID>
     <ehit1:AckTimeStamp ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:AckTimeStamp>
     <ehit1:StatusCode ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:StatusCode>
     <ehit1:ErrorCode ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:ErrorCode>
     <ehit1:ErrorMessage ns:id="?" ns:metadata="?" ns:linkMetadata="?">?</ehit1:ErrorMessage>

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) = 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.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s