ESB WSO2-在数据源查询中使用数组作为paramtype
我想这样的API向我的API发送请求:
{
"id": "22",
"code": "AXB23, ADR40, SMRS2"
}
并且我想在“ select ... where ... in ... in(axb23,adr40,smrs2)”中使用每个代码,但我不知道我不知道如何。 我发现在这里“ name =”代码“ paramtype =“ array” sqltype =“ string”/> 但这无效。 有什么建议吗?
编辑*: 这是我的api(不序列 - 忘记了原始帖子中请求的ID,我只有“代码”)
<inSequence>
<property expression="json-eval($..code)" name="code" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<selectTEST xmlns:xs="http://ws.wso2.org/dataservice/selectTEST">
<code>$1</code>
</selectTEST>
</format>
<args>
<arg evaluator="xml" expression="$ctx:code"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<header name="Action" scope="default" value="selectTEST"/>
<call>
<endpoint key="ep.select"/>
</call>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
</inSequence>
,这是我的数据服务:
<operation name="selectTEST" returnRequestStatus="true">
<call-query href="selectTEST">
<with-param name="code" query-param="code"/>
</call-query>
</operation>
<query id="selectTEST" useConfig="default">
<sql><![CDATA[
select x, y, z, w from mydatabase where code in (:code)
]]></sql>
<param type="IN" name="code" paramType="ARRAY" sqlType="STRING"/>
<result outputType="json">
{
"data": {
"records": [
{
"x": "$x",
"y": "$y",
"z": "$z",
"w": "$w"
}
]
}
}
</result>
</query>
我的请求:
{
"code": ["AXB23", "ADR40"]
}
I want to sent a request to my api like this:
{
"id": "22",
"code": "AXB23, ADR40, SMRS2"
}
And I want to use every code in a query like "SELECT ... WHERE ... IN(AXB23, ADR40, SMRS2)" in my datasource but I don't know how.
I found here a solution with <param type="IN" name="code" paramType="ARRAY" sqlType="STRING"/>
but it doesn't work.
Any suggestions?
EDIT*:
This is my api (inSequence - forget about the id from request in the original post, I just only have that 'code')
<inSequence>
<property expression="json-eval($..code)" name="code" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<selectTEST xmlns:xs="http://ws.wso2.org/dataservice/selectTEST">
<code>$1</code>
</selectTEST>
</format>
<args>
<arg evaluator="xml" expression="$ctx:code"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<header name="Action" scope="default" value="selectTEST"/>
<call>
<endpoint key="ep.select"/>
</call>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
</inSequence>
and this is my dataservice:
<operation name="selectTEST" returnRequestStatus="true">
<call-query href="selectTEST">
<with-param name="code" query-param="code"/>
</call-query>
</operation>
<query id="selectTEST" useConfig="default">
<sql><![CDATA[
select x, y, z, w from mydatabase where code in (:code)
]]></sql>
<param type="IN" name="code" paramType="ARRAY" sqlType="STRING"/>
<result outputType="json">
{
"data": {
"records": [
{
"x": "$x",
"y": "$y",
"z": "$z",
"w": "$w"
}
]
}
}
</result>
</query>
My request:
{
"code": ["AXB23", "ADR40"]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果使用数组类型参数,则应将值作为正确的JSON数组传递。这样的事情对您有用。
请求:
dataService查询
更新
完整的数据服务配置。
请注意,我已经指定了
&lt;资源方法=“ path”路径=“ student”&gt;
。资源用于RESTFULL INCOCACTICS,&lt;操作名称=“ selectTest” returnRequestStatus =“ true”&gt;
用于肥皂调用。我已经创建了Rentful and SOAP服务供您参考。以下是您可以调用它们的方式。注意:这里我直接调用数据服务。
RESTFULL调用。
SOAP服务调用
注意:在XML消息中,数组被描绘为重复元素,如上所示。
If you are using the array type parameters you should pass the values as a proper JSON array. Something like this will work for you.
The Request:
Dataservice Query
Update
The Full Dataservice config.
Note that I have specified a
<resource method="POST" path="student">
. resources are for RESTfull invocations, and<operation name="selectTEST" returnRequestStatus="true">
are for SOAP calls. I have created both RestFul and SOAP services for your reference. Following is how you can invoke them.Note: Here I'm directly calling the Dataservice.
RestFull Invocation.
SOAP Service Call
Note: In a XML message an Array is depicted as repeating elements as shown above.