To use custom mediator you need to first write a mediator, to do so click http://shriwithjava.blogspot.co.nz/2015/08/how-to-write-custom-mediator-in-wso2-esb.html 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
wso2esb-4.0.3\repository\components\lib\MyCustomMediator.jar
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" />
</proxy>
<sequence name="myCustom_IN">
<log level="full"/>
<property name="email"
action="set" value="abc"/>
<property name="pass"
action="set" value="pass"/>
<class
name="java.is.easy.MyCustomMediator"/>
<property name="email_id"
action="set" expression="//p:EmployeeDetails"
xmlns:p="http://java.is.easy/custommediator"/>
<log level="full"/>
<send/>
<drop/>
</sequence>
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.
No comments:
Post a Comment