【问题标题】:Call mediator end point type(XPath)调用中介端点类型(XPath)
【发布时间】:2019-08-26 22:39:16
【问题描述】:

在调用中介中,我们可以使用 XPath(来自响应)形成端点。但问题是端点没有调用。

<?xml version="1.0" encoding="UTF-8"?>
<api context="/xpath" name="call"  
 xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" protocol="http">
 <inSequence>
  <call>
 <endpoint key-expression="/root/a"/>
  </call>
  <respond/>
 </inSequence>
 <outSequence/>
 <faultSequence/>
 </resource>
</api>

以下回复来自邮递员。

<root>
<a>http://www.mocky.io/v2/5ca6db71340000132f76b192</a>
</root>

预期响应:

  <root>
 <name>abcd</name>
  <no>82382832</no>
  </root>

【问题讨论】:

    标签: wso2 wso2esb wso2is wso2-am wso2carbon


    【解决方案1】:

    首先,当使用解析端点(使用key-expression)时,我们不能直接给出URL[1]。我们必须预先定义端点,并且应该只在有效负载中提供端点的键。

    其次,对于解析 xpath 的 key-expression,应该预先构建消息。由于呼叫调解器不知道内容,因此它不会构建消息。因此,我们应该使用内容感知中介来构建消息。

    以下是可行的示例 inSequence。

    <inSequence>
         <log level="full"/>
         <call>
            <endpoint key-expression="//a"/>
         </call>
         <respond/>
      </inSequence>
    

    现在payload应该是这样的

    <root>
        <a>testEndpoint</a>
    </root>
    

    编辑: 应使用后端 url 定义名为“testEndpoint”的端点。

    您需要定义一个端点[2]。例如,我使用的是address endpoint。

    <endpoint xmlns="http://ws.apache.org/ns/synapse" name="testEndpoint">
     <address uri="http://www.mocky.io/v2/5ca6db71340000132f76b192">
        <suspendOnFailure>
           <progressionFactor>1.0</progressionFactor>
        </suspendOnFailure>
        <markForSuspension>
           <retriesBeforeSuspension>0</retriesBeforeSuspension>
           <retryDelay>0</retryDelay>
        </markForSuspension>
     </address>
    </endpoint>
    

    【讨论】:

    • 对不起,我不是很清楚,你能用一些实用的代码解释一下吗?我尝试使用注册表,但它对我不起作用。
    • 在注册表中保存端点是可选的。请参考编辑。
    【解决方案2】:

    试试这个。我在 Postman 中收到了所需的响应,但您应该使用 POST 方法,因为您的请求有一个 Body。

    <api xmlns="http://ws.apache.org/ns/synapse" name="call" context="/xpath">
       <resource methods="POST">
          <inSequence>
             <property name="uri.var.httpendpointurl" expression="$body/root/a" scope="default" type="STRING"/>
             <call>
                <endpoint>
                   <http uri-template="{uri.var.httpendpointurl}"/>
                </endpoint>
             </call>
             <respond/>
          </inSequence>
          <outSequence/>
          <faultSequence/>
       </resource>
    </api>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多