Question

I have WSO2 DSS set up to return data like this:

<Products>
   <Product>
      <SKU>12345678910123</SKU>
      <Item>123456</Item>
      <ItemName>My Product Name</ItemName>
   </Product>
</Products>

If there is no data to return I simply get the following:

<Products xmlns="http://data.mydomain.com/wso2/Products/getSKUinfo"/>

I have WSO2 ESB Pass Through Proxy set up to connect to the above service. When I hit the service in a URL like esbhost.domain.com/services/Products/SKU/12345678910123 I get the above. What I'd like to do is add a "Status" node (or whatever it's called) to essentially return this:

<Products>
   <Status>1</Status>
   <Product>
       <SKU>12345678910123</SKU>
       <Item>123456</Item>
       <ItemName>My Product Name</ItemName>
   </Product>
</Products>

If there isn't a match/no data to return I'd like the response to be:

<Products>
   <Status>0</Status>
</Products>

Is this possible to do in WSO2 ESB? Or do I need to add something in WSO2 DSS service?

Please pardon me if I'm not using the right terminology.

Thanks, Jared

Was it helpful?

Solution

Yes it can be done in the ESB. Basically in the "outSequence" of that proxy service, you can simply use the filter mediator, to check payload using XPath to check whether there isn't a match or no data is there. So from the filter mediator, in their separate paths, you can build up a message using the enrich mediator and add the necessary elements you need, like the 0 and so on. So basically in the filter mediator "true" path, you can save the "Product" element in a property, and add it later to the last created element in the message body using enrich. You may want to check out the ESB samples to get a feeling on how these mediators work.

Cheers, Anjana.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top