我是WSO2 esb的新手.我想创建一个api,我想在其中添加从api Url到端点url的动态参数.
我的终点网址就像 http://example.com/api/sync/{session_id}.json
我试着创建api之类的
<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>
Run Code Online (Sandbox Code Playgroud)
在log中我得到uri.var.session的值但是在端点Uri-template上它没有附加.
请指导我如何将api uri-template中的{id}值附加到端点uri-template?
检查此示例 我建议您直接在uri-template上使用属性mediator adn使用字符串连接,而不是在uri-template中添加"variable + .json".
那是;
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
Run Code Online (Sandbox Code Playgroud)
在上面的表达式中,使用字符串连接来构造带有".json"结尾的完整变量.
请从您的 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>
Run Code Online (Sandbox Code Playgroud)