我想写下一个目标行动序列: 1.致电DSS以接收客户列表 2.通过单独调用另一个DSS服务来丰富每个客户。
所以,我认为我应该调用callout mediator,然后使用iterator迭代它的结果。但我无法理解我应该在迭代器中写什么。
另一个问题 - 我是对的,每次迭代的结果都会附在'客户'标记
详细说明:
从DSS返回的XML是下一个:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<customers xmlns="crm.crm.crm">
<customer>
<customerId>1</customerId>
<name>Customer #1</name>
<birthdate>2017-01-15T14:54:12.000+03:00</birthdate>
</customer>
</customers>
</soapenv:Body>
</soapenv:Envelope>
序列:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="BatchSequence" statistics="enable" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log description="">
<property name="text" value="Start batch seq"/>
</log>
<payloadFactory description="create dss request" media-type="xml">
<format>
<soapenv:Envelope xmlns:crm="crm.crm.crm" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<crm:getCustomers>
<crm:batchSize>3</crm:batchSize>
</crm:getCustomers>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<callout action="urn:getCustomers" description="dss: main object" initAxis2ClientOptions="false" serviceURL="http://192.168.3.32:9765/services/CrmDataService?wsdl">
<source type="envelope"/>
<target key="customers"/>
</callout>
<log description="">
<property expression="get-property('customers')" name="text"/>
</log>
<iterate description="Enrich customers" expression="/soapenv:Envelope/soapenv:Body/customers/customer" id="iterateId" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<target>
<sequence>
<property description="customerId" expression="/customerId" name="customerID" scope="default" type="STRING"/>
<log description="">
<property expression="get-property('customerID')" name="text"/>
</log>
</sequence>
</target>
</iterate>
<log description="">
<property name="text" value="End batch seq"/>
</log>
</sequence>
输出:
[2017-01-27 10:17:17,371] INFO - LogMediator To:,MessageID:urn:uuid:d628e361-beb8-4c26-b06d-3901227ad76a,Direction:request,text = Start batch seq [2017-01-27 10:17:18,558] INFO - LogMediator To:,MessageID:urn:uuid:d628e361-beb8-4c26-b06d-3901227ad76a,Direction:request,text = 1Customer#12017-01-15T14:54: 12.000 + 03:002Customer#22016-12-16T14:54:20.000 + 03:003客户#32016-10-27T14:54:21.000 + 03:00 [2017-01-27 10:17:18,559] WARN - RuntimeStatisticCollector事件在事件收集完成后发生,事件 - urn_uuid_d628e361-beb8-4c26-b06d-3901227ad7 6a231160071781262
更新1 一些工作代码。不确定这是否正确,因为我在这里对PayloadFactory有点困惑..
<payloadFactory description="" media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>$1</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('customers')"/>
</args>
</payloadFactory>
<iterate continueParent="true" description="" expression="$body/crm:customers/crm:customer" sequential="true" xmlns:crm="crm.crm.crm">
<target>
<sequence>
<property expression="//crm:customerId" name="customerID" scope="default" type="STRING"/>
<log>
<property expression="get-property('customerID')" name="text"/>
</log>
</sequence>
</target>
</iterate>
更新2 我想出了一个主要问题 - 标注调解员并没有&#39;把响应放在信封上下文中(如果我理解的话)。因此,我们不能仅使用属性将其与迭代器链接,因此,在这种情况下,我们应该使用像Payload工厂这样的smth链接它们。不是很有用 如果smbdy知道如何更简单(直接将属性传递给迭代器) - 请写信给我。 解决方案 - 使用Call medator。工作正常。
感谢所有人!
答案 0 :(得分:0)
dss响应中的xml节点属于名称空间“crm.crm.crm”,您必须在xpath中引用它
使用iterate mediatior,如果要保留源有效负载,则必须使用名为preservePayload =“true”的属性,并告知xml framents必须使用attachPath ortherwise属性附加到何处,在Interate的序列中,您将只有肥皂体中的xml片段
这是一个在不保留源有效负载的情况下工作的示例:
<iterate xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:crm="crm.crm.crm" expression="$body/crm:customers/crm:customer" id="iterateId">
<target>
<sequence>
<property expression="$body/crm:customer/crm:customerId" name="customerID" scope="default" type="STRING"/>
<log>
<property expression="get-property('customerID')" name="text"/>
</log>
</sequence>
</target>
</iterate>
默认情况下,迭代后的调解器不会被执行。如果要继续调解,请使用属性continueParent =“true”
答案 1 :(得分:0)
您可以使用嵌套查询。请查看此帖子https://docs.wso2.com/display/DSS351/Nested+Query+Sample