Saturday, August 8, 2015

How to use custom mediator in WSO2 ESB

To use custom mediator you need to first write a mediator, to do so click to write custom mediator.
We have already created a mediator in previous blog now we have to use this in ESB. After writing class mediator export it as jar file and put this in below folder.

Folder to put Custom Mediator Jar File


We have created jar file from the java class file with the name of ‘MyCustomMediator.jar’ and put this in above folder.
In the synapse file I have created a proxy named “myCustom” in which we will invoke custom mediator.

Synapse Code:

 <proxy name="myCustom" transports="https http" startOnLoad="true" trace="disable" statistics="enable">
<target inSequence="myCustom_IN" />

<sequence name="myCustom_IN">
<log level="full"/>
<property name="email" action="set" value="abc"/>
<property name="pass" action="set" value="pass"/>
<class name=""/>

<property name="email_id" action="set" expression="//p:EmployeeDetails" xmlns:p=""/>

<log level="full"/>

In this above code I have not written proper code or any error handling which can be put in your logic but this is just to call custom mediator.

Now if you call this service you can see that in logs it is showing the details as expected. This mediator is fetching the record from the database and showing this to ESB. Now you can use this data as required in your logic.