【问题标题】:How to create xPath for soap header and body如何为肥皂标题和正文创建 xPath
【发布时间】:2019-07-08 11:16:28
【问题描述】:

我正在尝试为具有标题和正文的肥皂请求创建一个存根,以下是肥皂请求:

<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns3="http://example.com/ws/Namespaces/CustomerCareProductAndInsurance/Types/Public/CommonDataModel.xsd"
    xmlns:inq="http://example.wsproduct.com/ws/Namespaces/Container/Public/InquireProductDetailsRequest.xsd"
    xmlns="http://example.wsproduct.com/ws/Namespaces/Types/Public/MessageHeader.xsd">
    <soap:Header>
        <MessageHeader>
            <TrackingMessageHeader>
                <version>224</version>
            </TrackingMessageHeader>
        </MessageHeader>
    </soap:Header>
    <soap:Body>
        <inq:InquireProductDetailsRequest>
            <inq:ProductSelector>
                <inq:code>013881004138416</inq:code>
            </inq:ProductSelector>
        </inq:InquireProductDetailsRequest>
    </soap:Body>
</soap:Envelope>

以下是我使用 xPath 匹配器创建的存根,但它无法正常工作,而且我每次都得到 body 不匹配。

 {
    "request": {
        "method": "POST",
        "url": "/inquireProductDetails",
        "headers": {
            "Content-Type": {
                "contains": "text/xml"
            }
        },
        "bodyPatterns": [
            {
                "matchesXPath": "//version='224'"
            },{
                "matchesXPath": "//code='013881004138416'"
            }
        ]
    },
    "response": {
        "transformers": [
            "response-template"
        ],
        "bodyFileName": "productDetails-Success-Response.xml",
        "status": 200
    }
}

有人可以帮助为上述肥皂请求创建匹配的 xPath。提前致谢!!

【问题讨论】:

    标签: xpath wiremock


    【解决方案1】:

    试试这个

    {
        "request": {
            "method": "POST",
            "url": "/inquireProductDetails",
            "headers": {
                "Content-Type": {
                    "contains": "text/xml"
                }
            },
           "bodyPatterns": [
                {
                    "matchesXPath": "//*[local-name()='code'][text()='224']"
                },{
                    "matchesXPath": "//*[local-name()='version'][text()='013881004138416']"
                }
            ]
        },
        "response": {
            "transformers": [
                "response-template"
            ],
            "bodyFileName": "productDetails-Success-Response.xml",
            "status": 200
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-14
      相关资源
      最近更新 更多