Thursday, November 22, 2012

Pick Payload Factory from registry in WSO2 ESB

Payload-factory mediator does is transforming message content which is also known as payload, in between client and the actual server. Incoming messages coming from the client can be transformed in to a format expected by the server by using payload-factory mediator. Then again response message can be formatted in a way that client can understand.

Payload-factory mediator has two elements namely format and args. Currently these two elements of payload-factory are defined inline. With my implementation I provide an option to pick the configuration from registry when format element is defined. What I did was, make available two options to define the format of payload factory. They are “Define inline” and pick from registry.

This project consists of mainly two parts which are back-end implementation and User Interface (UI) implementation. I started the project with back-end implementation. There were PayloadFacoryMeadiator class, PayloadFacoryMeadiatorSerializer class and PayloadFacoryMeadiatorFactory class. When payload factory is created PayloadFacoryMeadiatorSerializer serialize the payload-factory as an OMElement. When payload-factory is loaded back OMElement will be extracted by PayloadFacoryMeadiatorFactory.

When payload-factory is configured to get the format from registry, a key should be provided in the format tag. This key is the location of the format configuration file in the registry. The key is saved in PayloadFacoryMeadiator as an attribute. When transforming client’s message to the server expected format, if format is dynamic (pick from registry), format should be taken from MessageContext inside mediate method. Below figure shows how format is picked from MessageContext. Here synCtx means an instance of Message Context.

Below is the payload-factory configuration for ESB synapse configuration when format is dynamic. Here “conf” is referred to as configuration registry. Configuration of the format, dynamic_payload_1.xml, is saved inside a directory called payloadFactory in configuration directory. Configuration file’s location is given as the key of the format as described above. “args” tag defines the arguments passed to the payload-factory mediator.

<format key="conf:/payloadFactory/dynamic_payload_1.xml"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"

Below figure shows the User Interface which I created for payload-factory.


  1. I would like to do this.

    We are using ESB v4.6.0 and those options are not available to us. I tried following the code and not go through the editor but it did not work either.

    How can we accomplish this using version 4.6.0?

  2. Hi Scott,

    these patches are not applied yet to ESB 4.6 version. You can try it out applying the given below patches to the source code. Here is the link to download the relevant patches.

  3. Hi Sajini De Silva,

    Is there any custom payload factory , if there or possible Could you please explain me.

    1. My aim is for retrieving the 'n' of rows from data service server(when connect to Database).

    2. Is this payload factory support XSD(xml schema definition) also.

    Could you please help me.

    Thanks in Advance

    1. Hi Anil,

      Payload factory only support transforming fixed xml message to transform repetitive xml messages. You can iterate within XSLT using xsl:for-each and perform transformation.

  4. This comment has been removed by the author.

  5. Is it possible to use a wildcard within the "key" attribute for payloadFactory/format?