我試圖從SOAP請求XML中將一些值複製到SOAP響應XML文件中。使用groovy將SOAP UI中的值複製到SOAP UI響應中
考慮以下請求和響應XML以供參考:
<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......
和響應XML是:
<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>
我創建了兩個動態VAR這裏$ {ID}和$ {}的元數據。
我試圖複製。現在的ID和元數據屬性來設置這些值從請求到響應我使用下面的腳本:
def req = new XmlSlurper().parseText(mockRequest.requestContent)
requestContext.id = [email protected];
requestContext.metadata = [email protected]data;
但它不返回任何值。有人能幫我弄清楚我在這裏做錯了嗎?
此外,如果我想複製很多(考慮50+)從請求值到響應值,那麼是否有任何簡單的方法,而不是創建50+變量?因爲在我的情況下,我不得不將所有請求中的值複製到響應消息中。
你是否在mockService的'onRequest script'上使用這個腳本? – albciff
是的,我正在用soap ui編寫mockservice腳本 – Madhusudan