【发布时间】:2019-07-24 23:03:00
【问题描述】:
我想要达到的目标:
使用 Enterprise Integrator API,我想将来自两个数据服务端点(称为 ORDERS 和 METADATAS)的数据组合成一个自定义对象,如下所示:
[
{
Order: {},
Metadata: {}
}, ...
]
API 目前只接受一个参数,USER_ID。
当我在阻塞模式下运行<call> 调解器时,我遇到了以下问题:
Current Params: {USER_ID={1,1}, ID=test}
或
Current Params: {USER_ID={test,1}}
在非阻塞模式下,第一次调用成功,第二次调用无法进行。它似乎无法从 URL 访问 USER_ID 参数,也无法从存储的属性访问。我认为属性应该保持值?
需要注意的是,日志中的值是 100% 准确的(USER_ID 属性显示的是正确的值)。
INFO {org.apache.synapse.mediators.builtin.LogMediator} - _TEST = 1, _TEST2 = 1, _TEST3 = 1
以下是我目前对 inSequence 的了解:
<resource methods="GET" uri-template="/test?USER_ID={USER_ID}">
<inSequence>
<property expression="get-property('query.param.USER_ID')" name="USER_ID" scope="default" type="STRING"/>
<property expression="$url:USER_ID" name="uri.var.USER_ID" scope="default" type="STRING"/>
<call blocking="true">
<endpoint>
<http method="get" statistics="enable" trace="enable" uri-template="https://localhost:8243/services/ORDERS_DataService/user/{query.param.USER_ID}"/>
</endpoint>
</call>
<log level="custom">
<property expression="get-property('USER_ID')" name="_TEST"/>
<property expression="get-property('query.param.USER_ID')" name="_TEST2"/>
<property expression="get-property('uri.var.USER_ID')" name="_TEST3"/>
</log>
<enrich>
<source clone="false" type="body"/>
<target property="_ORDERS" type="property"/>
</enrich>
<filter regex="200" source="get-property('axis2', 'HTTP_SC')">
<then>
<log level="custom">
<property name="switchlog" value="Case: first call successful"/>
</log>
<call blocking="true">
<endpoint>
<http method="get" statistics="enable" trace="enable" uri-template="https://localhost:8243/services/ORDERS_DataService/metadata/user/{query.param.USER_ID}"/>
</endpoint>
</call>
<enrich>
<source clone="false" type="body"/>
<target property="_METADATAS" type="property"/>
</enrich>
<log level="custom">
<property expression="get-property('_METADATAS')" name="_METADATAS"/>
</log>
</then>
<else/>
</filter>
</inSequence>
</resource>
我尝试了什么?
在 <call>s 的两个 uri 模板中使用 {USER_ID}、{uri.var.USER_ID}、{$url:USER_ID} 和 {query.param.USER_ID}。
尝试了非阻塞和阻塞模式,得到不同的结果。
我的问题只是(目前)调用两个序列并分配给属性。
我计划通过迭代将它们全部组合在一起,如下所示,将属性映射到我正在寻找的数组中的每个项目:
<!-- Assuming iterate provides _ORDER and _METADATA whilst looping -->
<format>
{
"Order":"$1",
"Metadata":"$2"
}
</format>
<args>
<arg expression="get-property('_ORDER')"/>
<arg expression="get-property('_METADATA')"/>
</args>
如果这不起作用,我打算对这两个项目评估 XSLT 转换,但我还没有想到那么远,卡在两个调用不正常工作。
【问题讨论】: