以下是我要解决的问题:
输入消息如下所示:
<PurchaseOrder xmlns="http://example.com/samples">
<Header>
<VendorData>
<VendorNumber>123456</VendorNumber>
</VendorData>
</Header>
<Body>
<LineItem>
<ItemNumber>111222333</ItemNumber>
</LineItem>
<LineItem>
<ItemNumber>333224444</ItemNumber>
</LineItem>
<LineItem>
<ItemNumber>123456789</ItemNumber>
</LineItem>
</Body>
</PurchaseOrder>
...并且输出消息应如下所示:
<PurchaseOrder xmlns="http://example.com/samples">
<Header>
<VendorData>
<VendorNumber>123456</VendorNumber>
</VendorData>
<VendorTerms>
<Discount>
<Description>15% NET 10</Description>
<DiscountDays>10</DiscountDays>
</Discount>
<Days>30</Days>
<TermsID>001</TermsID>
</VendorTerms>
</Header>
<Body>
<LineItem>
<ItemNumber>111222333</ItemNumber>
<SKU>ABC123PDQ789</SKU>
<Cost>9.99</Cost>
<Description>Widget, Small</Description>
</LineItem>
<LineItem>
<ItemNumber>333224444</ItemNumber>
<SKU>0000143214</SKU>
<Cost>99.99</Cost>
<Description>Big Ticket Item</Description>
</LineItem>
<LineItem>
<ItemNumber>123456789</ItemNumber>
<SKU>01121245245</SKU>
<Cost>15.99</Cost>
<Description>Widget Bundle, Large (10)</Description>
</LineItem>
</Body>
</PurchaseOrder>
...通过调用其他服务获得附加信息。
下面是我正在尝试的代理服务定义,迭代介体外部的富集调解器按预期工作。它是迭代调解器内部的丰富调解器,它没有像我预期的那样工作。我的印象是我不得不使用聚合调解员将所有东西重新组合在一起。
我已经通过WSO2和Synapse示例查看了这个问题,并且他们都假设您正在使用带有发送中介的迭代中介来调用其他服务,这与我在这里所做的不同。
代理服务定义:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="DSS_MockPOC" transports="https,http" statistics="enable" trace="enable" startOnLoad="true">
<target>
<inSequence>
<property xmlns:ex="http://example.com/samples" name="VendorNumber" expression="//ex:PurchaseOrder/ex:Header/ex:VendorData/ex:VendorNumber" scope="default" type="STRING"/>
<callout serviceURL="local:///services/Mock_TermsLookup/" action="urn:mediate">
<source type="envelope"/>
<target key="TermsResponse"/>
</callout>
<enrich>
<source clone="true" xpath="synapse:get-property('TermsResponse')"/>
<target xmlns:ex="http://example.com/samples" action="sibling" xpath="//ex:PurchaseOrder/ex:Header/ex:VendorData"/>
</enrich>
<iterate xmlns:ex="http://example.com/samples" continueParent="true" id="LineItemIterator" preservePayload="true" attachPath="//ex:PurchaseOrder/ex:Body" expression="//ex:PurchaseOrder/ex:Body/ex:LineItem" sequential="true">
<target>
<sequence>
<property name="ItemLookupRequest" expression="$body" scope="default" type="OM"/>
<callout serviceURL="local:///services/Mock_ItemLookup/" action="urn:mediate">
<source key="ItemLookupRequest"/>
<target key="ItemLookupResponse"/>
</callout>
<enrich>
<source type="property" clone="true" property="ItemLookupResponse"/>
<target xpath="//ex:LineItem"/>
</enrich>
</sequence>
</target>
</iterate>
<aggregate id="LineItemIterator">
<correlateOn xmlns:ex="http://example.com/samples" expression="//ex:PurchaseOrder/ex:Header"/>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:ex="http://example.com/samples" expression="//ex:PurchaseOrder/ex:Body/ex:LineItem">
<log level="full"/>
</onComplete>
</aggregate>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<header name="To" action="remove"/>
<send/>
</inSequence>
</target>
<description></description>
</proxy>
最后,这是我在调用此服务时目前获得的内容。通过日志记录,我可以看到迭代介体正在发送和接收正确的信息;结果根本不会传播到返回消息。
<PurchaseOrder xmlns="http://example.com/samples">
<Header>
<VendorData>
<VendorNumber>123456</VendorNumber>
</VendorData>
<VendorTerms>
<Discount>
<Description>15 % NET 10</Description>
<DiscountDays>10</DiscountDays>
</Discount>
<Days>30</Days>
<TermsID>001</TermsID>
</VendorTerms>
</Header>
<Body>
<LineItem>
<ItemNumber>111222333</ItemNumber>
</LineItem>
<LineItem>
<ItemNumber>333224444</ItemNumber>
</LineItem>
<LineItem>
<ItemNumber>123456789</ItemNumber>
</LineItem>
</Body>
</PurchaseOrder>