- The following steps will explain how can a payload be replaced with a different payload using PayloadFactory mediator:
<property name="id" expression="//id" scope="default" type="STRING"/>
<property name="name" expression="//name" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<m:response xmlns:m="http://services.samples">
<m:customer>
<m:id>$1</m:id>
<m:name>$2</m:name>
</m:customer>
</m:response>
</format>
<args>
<arg evaluator="xml" expression="$ctx:id"/>
<arg evaluator="xml" expression="$ctx:name"/>
</args>
</payloadFactory>
Where in the argument, the id and name are set using the message context. From the request or response, these id and name can be parsed through the xpath and set it as a property as above.
- The following steps will explain how can a payload be replaced with a different payload using Enrich mediator:
<property name="id" expression="//id" scope="default" type="STRING"/>
<property name="name" expression="//name" scope="default" type="STRING"/>
<enrich>
<source type="inline">
<response >
<customer>
<id>xxx</id>
<name>xxxx</name>
</customer>
</response>
</source>
<target type="body"/>
</enrich>
<enrich>
<source type="property" clone="true" property="id"/>
<target xpath="//s:response/s:customer/s:id" xmlns:s="http://ws.apache.org/ns/synapse"/>
</enrich>
<enrich>
<source type="property" clone="true" property="message"/>
<target xpath="//s:response/s:customer/s:name" xmlns:s="http://ws.apache.org/ns/synapse"/>
</enrich>
In this case, the first enrich will replace the body with the specified payload. Then the second and third enrich will replace the values of the element in the body using the available property.
No comments:
Post a Comment