具有动态参数的 WSO2 ESB REST
WSO2 ESB REST with dynamic parameters
我构建了一个 API 应该采用如下动态参数,
<api xmlns="http://ws.apache.org/ns/synapse" name="MrlDatabaseAPI" context="/rest">
<resource methods="OPTIONS GET" uri-template="/reportNotes?country={country}&pesticide={pesticide}&crop={crop}">
<inSequence>
<send>
<endpoint>
<http method="GET" uri-template="http://172.17.100.113/MRLService/rest/v1/reportNotes?country={uri.var.country}&pesticide={uri.var.pesticide}&crop={uri.var.crop}"/>
</endpoint>
</send>
</inSequence>
现在资源只有在传递所有三个参数时才有效,http://localhost/rest/reportNotes?country=AUS&pesticide=ABA3000&crop=22020100。
如何调整 API 并使其接受任意两个参数,例如:
http://localhost/rest/reportNotes?country=AUS&pesticide=ABA3000 or http://localhost/rest/reportNotes?country=AUS&crop=22020100
Restful 网络服务本身可以接受任意数量的参数。
谢谢,
肖恩
根据你的配置,参数个数不多也无法求解。
您可以通过 "filter" 调解员
解决问题
例如:
<filter source="boolean(get-property('uri.var.pesticide'))" regex="false">
<then>
<send>
<endpoint>
<http method="GET" uri-template="http://172.17.100.113/MRLService/rest/v1/reportNotes?country={uri.var.country}&crop={uri.var.crop}"/>
</endpoint>
</send>
</then>
<else>
<drop/>
</else>
</filter>
您可以使用此调解器实现您的场景。
我构建了一个 API 应该采用如下动态参数,
<api xmlns="http://ws.apache.org/ns/synapse" name="MrlDatabaseAPI" context="/rest">
<resource methods="OPTIONS GET" uri-template="/reportNotes?country={country}&pesticide={pesticide}&crop={crop}">
<inSequence>
<send>
<endpoint>
<http method="GET" uri-template="http://172.17.100.113/MRLService/rest/v1/reportNotes?country={uri.var.country}&pesticide={uri.var.pesticide}&crop={uri.var.crop}"/>
</endpoint>
</send>
</inSequence>
现在资源只有在传递所有三个参数时才有效,http://localhost/rest/reportNotes?country=AUS&pesticide=ABA3000&crop=22020100。
如何调整 API 并使其接受任意两个参数,例如: http://localhost/rest/reportNotes?country=AUS&pesticide=ABA3000 or http://localhost/rest/reportNotes?country=AUS&crop=22020100
Restful 网络服务本身可以接受任意数量的参数。
谢谢, 肖恩
根据你的配置,参数个数不多也无法求解。
您可以通过 "filter" 调解员
解决问题例如:
<filter source="boolean(get-property('uri.var.pesticide'))" regex="false">
<then>
<send>
<endpoint>
<http method="GET" uri-template="http://172.17.100.113/MRLService/rest/v1/reportNotes?country={uri.var.country}&crop={uri.var.crop}"/>
</endpoint>
</send>
</then>
<else>
<drop/>
</else>
</filter>
您可以使用此调解器实现您的场景。