Regex WireMock bodyPatterns XML匹配正则表达式
我正在使用WireMock来模拟SOA服务,但我对bodyPattern XML有一个问题,我可以在XML中使用正则表达式吗 我的请求头根据请求时间而变化,我只想匹配头中的任何内容Regex WireMock bodyPatterns XML匹配正则表达式,regex,xml,wiremock,Regex,Xml,Wiremock,我正在使用WireMock来模拟SOA服务,但我对bodyPattern XML有一个问题,我可以在XML中使用正则表达式吗 我的请求头根据请求时间而变化,我只想匹配头中的任何内容 { "request" : { "url" : "/service/v1/WebService", "method" : "POST", "bodyPatterns" : [ { "equalToXml" :"\\Q<SOAP-ENV:Envelope xmlns:SOA
{
"request" : {
"url" : "/service/v1/WebService",
"method" : "POST",
"bodyPatterns" : [ {
"equalToXml" :"\\Q<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header>
<SOAP-ENV:Header>
I want to match whatever inside header.
</SOAP-ENV:Header>
} ]
},
{
“请求”:{
“url”:“/service/v1/WebService”,
“方法”:“发布”,
“bodyPatterns”:[{
“equalToXml”:“\\Q
我想匹配头球里面的任何东西。
} ]
},
您可以使用Xpath获得相同的结果
"bodyPatterns": [
{
"matchesXPath": "your xpath"
}
例如,您的请求如下所示
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ex="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<ex:somebody>
<ex:input>
<ex:name>John</ex:name>
<ex:phone>7414444</ex:phone>
<ex:role>teacher</ex:role>
</ex:input>
</ex:somebody>
</soapenv:Body>
约翰
7414444
老师
那么你的JSON文件可能是
{
"request" : {
"url" : "/service/v1/WebService",
"bodyPatterns" : [ {
"matchesXPath": "//ex:input[ex:name=\"John\" and xw:phone=\"7414444\"]",
"xPathNamespaces" : {
"ex" : "http://example.com"
}
}]
},
"response" : {
"status" : 200,
"headers": {
"Content-Type": "text/xml;charset=UTF-8"
},
"body" : "<Abody>"
}}
{
“请求”:{
“url”:“/service/v1/WebService”,
“bodyPatterns”:[{
“matchesXPath”:“//ex:input[ex:name=\“John\”和xw:phone=\“7414444\”,
“xPathNamespaces”:{
“例如”:http://example.com"
}
}]
},
“答复”:{
“地位”:200,
“标题”:{
“内容类型”:“text/xml;charset=UTF-8”
},
“正文”:”
}}