7

我是 WSO2 esb 的新手。我想创建一个 api,我想在其中添加一个从 api Url 到端点 url 的动态参数。

我的终点网址就像http://example.com/api/sync/{session_id}.json

我试图创建像

<api name="rest" context="/sync">
          <resource methods="GET" uri-template="/{id}">
             <inSequence>
             <log level="full">
                <property xmlns:ns="http://org.apache.synapse/xsd"
                          name="uri.var.session"
                          expression="get-property('uri.var.id')"
                          scope="axis2"/>
                </log>
                <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
                <send>
                   <endpoint name="Mecars">
                      <http trace="enable"
                            method="get"
                            uri-template="http://example.com/sync/{+uri.var.session}.json"/>
                   </endpoint>
                </send>
            </inSequence>
          </resource>
       </api>

在日志中,我得到了 uri.var.session 的值但是在端点 Uri-template 上它没有附加。

请指导我如何将 api uri-template 中的 {id} 值附加到端点 uri-template?

4

4 回答 4

5

检查此示例 ,我建议您在属性调解器处进行字符串连接,并直接在 uri-template 处使用它,而不是在 uri-template 处添加“变量 +.json”。

那是;

<property xmlns:ns="http://org.apache.synapse/xsd"
                          name="uri.var.session"
                          expression="get-property('uri.var.id')"
                          scope="axis2"/>

在上面的 for 表达式中,进行字符串连接以构造以“.json”结尾的完整变量。

于 2014-01-02T08:59:13.093 回答
4

请从您的 http 端点中删除“+”符号。它对我来说工作正常

示例 API

   <api xmlns="http://ws.apache.org/ns/synapse" name="Elastic Search Using NPI"     context="/api/npi/professional/npi.json">
 <resource methods="OPTIONS GET" uri-template="/{npi}">
    <inSequence>
       <log level="full">
        <property name="uri.var.npi" expression="get-property('uri.var.npi')"></property>
      </log>
     <send>
        <endpoint>
           <http method="get" uri-template="example.com/{uri.var.npi}"></http>
        </endpoint>
     </send>
    </inSequence>     
  </resource>
</api>
于 2014-03-18T10:47:42.837 回答
3

更改 http 端点 uri 模板,如下所示。

<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>

以下是修改后的 api 配置。

<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/sync">
 <resource methods="GET" uri-template="/{id}">
    <inSequence>
     <log level="full">
        <property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.session" expression="get-property('uri.var.id')"></property>
     </log>
     <property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
     <send>
        <endpoint name="Mecars">
           <http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
        </endpoint>
     </send>
  </inSequence>
 </resource>
</api>
于 2014-01-07T17:58:17.930 回答
1

您可以按如下方式在属性中介处进行字符串连接。

<property xmlns:ns="http://org.apache.synapse/xsd"
                      name="uri.var.session"
                      expression="fn:concat(get-property('uri.var.id'),'.json')"
                      scope="axis2"/>
于 2014-03-22T04:46:26.633 回答