Hi All, I am developing a new Mediator for ESB as a pet project. After noticing some draw backs in Payload Factory I thought of writing this one.
Code can be found at : https://github.com/asanka88/VelocityTemplateMediator @ESB Team: If this make any sense, I am more than happy to contribute this with more improvements. This is still under development. I will upload samples soon. Your feedback is highly appreciated. Why Velocity Template Mediator ? Currently synapse comes with built in payloadFactory mediator. But there are several drawbacks in it. 1 Doesn’t support arrays : You cannot iterate though an array/collection and add those elements to the payload. 2 Doesn’t support conditional expressions: In case you want to add elements based on conditions payloadFactory doesn’t support it. 3 Readability is less since numbered placeholders like $1,$2 are used <https://github.com/asanka88/VelocityTemplateMediator#how-velocity-template-mediator-solve-them>How Velocity Template Mediator solve them? Velocity template mediator uses well known Apache Velocity as the template engine. You can do whatever you can do with Velocity in side this. Iterate through collections, check conditions etc. In addition to that since we are using place holders like $name,$age for the variables ,so it improves the readability as well. On the other hand, there was no such a thing in Synapse to create a property out of a template. For Example: When you call a soap back end, suppose you have to send a user name token in SOAP Header. Suppose there are several back end calls you need to make and in every call you need to pass the user name token. With the payload factory , you will have to create that part every time. Instead if you can create a property one time using a template and save it in the message context , you can reuse it without generating again and again. With the Velocity Template Mediator , it supports body,property,soap header,envelope as the targets. You can put the generated output to anyof these. And it supports both xml and json formats Sample Syntax <velocityTemplate media-type="xml|json"> <format> <person> <name>$name</name> <age>$age</age> </person> </format> <args> <arg name="name" expression="$ctx:name" /> <arg name="age" expression="$ctx:age" /> </args> <target target-type="property|body|custom|header" name="propertyName" property-type="string|om" scope="synapse|axis2|operation" /> </velocityTemplate> Thanks, Asanka D -- *Asanka DissanayakeSoftware Engineer* *WSO2 Inc. - lean . enterprise . middleware | wso2.com <http://wso2.com/>* *email: asan...@wso2.com <ruch...@wso2.com>, blog: cyberwaadiya.blogspot.com <http://cyberwaadiya.blogspot.com>, asankastechtalks.wordpress.com <http://asankastechtalks.wordpress.com> mobile: +94 71 8373821*
_______________________________________________ Architecture mailing list Architecture@wso2.org https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture