0

Here's the problem I'm trying to solve:

  1. receive a message
  2. enrich the message by calling another service to obtain information (the other service happens to be a WSO2 Data Service, but using a mock proxy works the same); see here for info on the enrich pattern
  3. send the message on its way

The input message looks like this:

<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>

... and the output message should look like this:

<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>

... where the additional information is obtained by calling other services.

Below is the proxy service definition I am trying, and the enrich mediator outside of the iterate mediator works as expected. It's the enrich mediator inside the iterate mediator that is not working as I expected. I was under the impression that I had to use an aggregate mediator to tie everything back together.

I've looked through WSO2 and Synapse examples for such a problem, and they all assume that you are using the iterate mediator with a send mediator to call other services, which is not the same as what I'm doing here.

Proxy service definition:

<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>

Finally, this is what I currently get when calling this service. Through logging, I can see that the iterate mediator is sending and receiving the correct information; the results are simply not propagated to the return message.

<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>
Thomas Ehardt
  • 155
  • 4
  • 11
  • Tom, is there a specific reason why you are using callout and not send for your service calls? – Chris Aug 07 '13 at 20:15
  • It is my (perhaps incorrect) understanding that this is the way to perform enrichment on the message. How would I do the same thing using a send mediator? – Thomas Ehardt Aug 08 '13 at 18:17

0 Answers0