【发布时间】:2015-10-29 15:28:24
【问题描述】:
我正在尝试将一些值从 SOAP 请求 XML 复制到 SOAP 响应 XML 文件中。
考虑以下请求和响应 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>
我在这里创建了两个动态变量 ${id} 和 ${metadata}。
我试图复制 .Now 的 id 和 metadata 属性,以将这些值从请求设置为响应,我正在使用以下脚本:
def req = new XmlSlurper().parseText(mockRequest.requestContent)
requestContext.id = req.Body.DeterminationRequest.MessageInformation.MessageID.@id;
requestContext.metadata = req.Body.DeterminationRequest.MessageInformation.MessageID.@metadata;
但它没有返回任何值。有人可以帮我弄清楚我在这里做错了什么吗?
另外,如果我想将请求中的许多(考虑 50 多个)值复制到响应中,那么有什么简单的方法可以代替创建 50 多个变量吗?因为就我而言,我必须将请求中的所有值复制到响应消息中。
【问题讨论】:
-
您是否在模拟服务中的
onRequest script上使用此脚本? -
是的,我正在为soap ui中的模拟服务编写这个脚本
标签: xml web-services groovy soapui