【问题标题】:Azure API Management Set-Body with liquid templateAzure API Management Set-Body with Liquid 模板
【发布时间】:2021-03-22 18:14:13
【问题描述】:

我有一个 SOAP 服务,我需要在将请求发送到后端服务之前向 XML 正文添加一个属性。

我的 Postman 请求如下:

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
  <Body>
    <gprnEnquiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somedomain.com">
      <gprn>123456</gprn>
      <registrationstatus>registrationstatus1</registrationstatus>
    </gprnEnquiry>
  </Body>
</Envelope>

我正在传递 text/xml 的 Content-Type 标头

我的 APIM 入站策略如下:

    <set-body template="liquid">
        <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
            <Body>
                <gprnEnquiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somedomain.com">
                    <gprn>{{body.gprnEnquiry.gprn}}</gprn>
                    <registrationstatus>{{body.gprnEnquiry.registrationstatus}}</registrationstatus>
                    <authKey>{{My-NamedValue}}</authKey>
                </gprnEnquiry>
            </Body>
        </Envelope>
    </set-body>

通过在 APIM 中启用请求和响应正文捕获,我可以看到来自请求的值正在输入,而响应输出时没有任何值。

后端请求

<Envelope
    xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <gprnEnquiry
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://www.somedomain.com">
            <gprn></gprn>
            <registrationstatus></registrationstatus>
            <authKey>xxxxxxxxxxx</authKey>
        </gprnEnquiry>
    </Body>
</Envelope>

有人知道为什么源请求中的值没有被映射到后端请求吗?

【问题讨论】:

    标签: azure azure-api-management apim


    【解决方案1】:

    好的,这里的答案是由于请求正文的格式以及 APIM 策略映射元素的方式。通过在请求中包含 和 Envelope 节点可防止 Liquid 模板正确映射值。

    此外,APIM 不允许您指定信封位于请求正文中,例如 {{envelope.body.gprnEnquiry.gprn}}。

    将请求正文更改为以下解决了该问题:

      <Body>
        <gprnEnquiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somedomain.com">
          <gprn>123456</gprn>
          <registrationstatus></registrationstatus>
        </gprnEnquiry>
      </Body>
    

    【讨论】:

      【解决方案2】:

      您的路径 {{body.gprnEnquiry.gprn}} 不正确。如果您使用此示例 SOAP 消息,您的路径应该是:{{body.Envelope.Body.gprnEnquiry.gprn}},因为肥皂正文不会自动链接。液体标签“body”代表您的完整请求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-05
        • 1970-01-01
        • 2017-07-12
        • 1970-01-01
        相关资源
        最近更新 更多