Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex WireMock bodyPatterns XML匹配正则表达式_Regex_Xml_Wiremock - Fatal编程技术网

Regex WireMock bodyPatterns 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

我正在使用WireMock来模拟SOA服务,但我对bodyPattern XML有一个问题,我可以在XML中使用正则表达式吗

我的请求头根据请求时间而变化,我只想匹配头中的任何内容

{
  "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”
},
“正文”:”
}}