调用中介者端点类型(XPath)

问题描述 投票:1回答:2

在call mediator中,我们可以使用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
2个回答
0
投票

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

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

以下是序列中的样本。

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

现在有效载荷应该是这样的

<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>

0
投票

试试这个。我在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>

Postman screeshot

© www.soinside.com 2019 - 2024. All rights reserved.