场景:请求包含多个包含详细信息的订单。将订单详细信息发送到后端服务并获取一个新的行号,在我应该像使用param之一那样使用创建详细信息
请求外观:
<OrderList>
<Order>
<target>MySQL</target>
<Sales>
<email>p@gmail.com</email>
</Sales>
<Details>
<Item><qty>1</qty><code>PR9</code></Item>
<Item><qty>2</qty><code>PR8</code></Item>
<Item><qty>3</qty><code>PR7</code></Item>
</Details>
</Order>
<Order>
<target>MySQL</target>
<Sales>
<email>j@gmail.com</email>
</Sales>
<Details>
<Item><qty>4</qty><code>PR6</code></Item>
<Item><qty>5</qty><code>PR5</code></Item>
<Item><qty>6</qty><code>PR4</code></Item>
</Details>
</Order>
.......
</OrderList>
序列:
<inSequence>
<!-- get source target data -->
<iterate expression="//Order" preservePayload="true">
<target>
<enrich>
<source clone="true" xpath="//Order"/>
<target property="OrderBackup" type="property"/>
</enrich>
<sequence>
<property expression="//target" name="SalesTarget" scope="default" type="STRING"/>
<property expression="//Sales/email" name="email" scope="default" type="STRING"/>
<filter regex="MySQL" source="$ctx:SalesTarget">
<then>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:dat="http://ws.wso2.org/dataservice" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<dat:addSalesOrder>
<dat:email>$1</dat:email>
</dat:addSalesOrder>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:email"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint key="SalesOrderEP"/>
</call>
**<enrich>
<source clone="true" type="body"/>
<target property="newRowID" type="property"/>
</enrich>**
<property expression="$ctx:newRowID > 0 " name="isCorrectResponse" scope="default" type="BOOLEAN"/>
<filter regex="true" source="$ctx:isCorrectResponse">
<then>
<enrich>
<source clone="true" property="OrderBackup" type="property"/>
<target type="body"/>
</enrich>
<iterate expression="//Details">
<target>
<sequence>
<property expression="//qty" name="qty" scope="default" type="STRING"/>
<property expression="//code" name="code" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('params:Code: ' ,$ctx:code, ' ;Qty: ',$ctx:qty)" name="info"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:dat="http://ws.wso2.org/dataservice" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<dat:addSalesDetails>
<dat:salesId>$1</dat:salesId>
<dat:qty>$2</dat:qty>
<dat:code>$3</dat:code>
</dat:addSalesDetails>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:newRowID"/>
<arg evaluator="xml" expression="$ctx:qty"/>
<arg evaluator="xml" expression="$ctx:code"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint key="SalesDetailsEP"/>
</call>
<!-- get response and log it -->
<aggregate>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete expression="//m0:UpdatedRowCount/Value" xmlns:m0="http://ws.wso2.org/dataservice">
<log level="full"/>
<drop/>
</onComplete>
</aggregate>
</sequence>
</target>
</iterate>
</then>
<else/>
</filter>
</then>
<else/>
</filter>
</sequence>
</target>
</iterate>
</inSequence>
我遇到第一次电话回复问题...我用了
<enrich>
<source clone="true" type="body"/>
<target property="newRowID" type="property"/>
</enrich>
在属性中保存新创建的行ID,并且我正确地在行
中获取它> <log level="custom">
> <property expression="fn:concat('NewRowID = ' ,$ctx:newRowID)" name="info"/>
> </log>
但是当我想在第二个有效载荷中使用它时它看起来无法解决它?!!?
错误:
DS错误消息:&#39; CallQuery.extractParams&#39;中的错误,找不到 参数类型:query-param name:salesId DS Code: INCOMPATIBLE_PARAMETERS_ERROR
我发现在有效载荷中,$ ctx:newRowID被解析为
<GeneratedKeys> xmlns="http://ws.wso2.org/dataservice"><Entry><ID>93</ID></Entry></GeneratedKeys>
而不仅仅是 93
我猜这是因为在丰富时我使用了源作为&#34; body&#34; ..但是当我试图获得像 xpath =&#34; //条目/ ID&#34; 的响应的xpath时我什么都没有
出了什么问题?
答案 0 :(得分:0)
问题在于丰富的中介需要名称空间,所以
<enrich>
<source clone="true" xmlns:n0="http://ws.wso2.org/dataservice" xpath="$body/n0:GeneratedKeys/n0:Entry/n0:ID"/>
<target property="newRowID" type="property"/>
</enrich>
做了魔术......所以总是把命名空间课程学到了