We have already created a WSO2 DSS service with the name of "EmployeeDataService". Now we have to call this service from WSO2 ESB.
WSO2 ESB is used to create proxy services.
Let’s create a proxy web service which calls a dataservice created in WSO2 DSS.
We have to modify synapse.xml to call dataservice in our proxy.
Synapse.xml is located at below location.
D:\..\wso2esb-4.0.3\repository\deployment\server\synapse-configs\default\synapse.xml
And the default synapse.xml has only “definitions” tag, we need to add some more configuration to call web service.
Before that lets see the structure of the Synapse.xml
Structure of Synapse.xml
WSO2 ESB Config structure:
=========================
synapse-configs
└── default
├── api
├── endpoints
├── event-sources
├── local-entries
├── priority-executors
├── proxy-services
├── registry.xml
├── sequences
│ ├── fault.xml
│ └── main.xml
├── synapse.xml
└── tasks
Modified Synapse.xml as mentioned below.
<!-- An empty flat synapse configuration shipped with the WSO2 ESB -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
<proxy name="DSS_EmployeeProxy" transports="http" startOnLoad="true" trace="disable" statistics="enable">
<target inSequence="DSS_EmployeeProxy_IN" outSequence="DSS_EmployeeProxy_OUT" faultSequence="CommonFaultHandler"/>
<publishWSDL key="DSS_EmployeeProxy_wsdl"/>
</proxy>
<sequence name="DSS_EmployeeProxy_IN">
<log level="full"/>
<send>
<endpoint key="DSS_EmployeeProxy_EPR"/>
</send>
</sequence>
<sequence name="DSS_EmployeeProxy_OUT">
<log level="full"/>
<send/>
</sequence>
<localEntry key="DSS_EmployeeProxy_wsdl" src="file:repository/conf/employee/EmployeeDataService.wsdl"/>
<endpoint name="DSS_EmployeeProxy_EPR">
<address uri="http://10.167.19.32:9763/services/EmployeeDataService">
<timeout>
<duration>20000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>101500,101501,101506,101507,101508</errorCodes>
<initialDuration>3000</initialDuration>
<progressionFactor>2.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<errorCodes>101504,101505</errorCodes>
<retriesBeforeSuspension>3</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
</address>
</endpoint>
<sequence name="CommonFaultHandler">
<log level="custom">
<property name="MESSAGE" value="Executing default "fault" sequence"/>
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
</log>
<header name="To" action="remove"/>
<drop/>
</sequence>
<!-- You can add any flat sequences, endpoints, etc.. to this synapse.xml file if you do
*not* want to keep the artifacts in several files -->
</definitions>
In above synapse file, we have added IN, OUT and Fault sequence and one end point (Mediators ). Let us look below that what is the use of these mediators
IN Sequence: This is the main sequence from which request starts, whenever a request comes In sequence is executed. We can also put some logic in this sequence but for this normal pass through proxy we have not added any logic.
OUT Sequence: After executing the In sequence or other sequence, at last OUT sequence is executed, in this sequence also logic can be implemented as required.
FAULT Sequence: This sequence is used to handle exception. If any exception comes this sequence is executed. We can supply any value or response as required.
End Point: A endpoint URL is provided in this mediator where request needs to be sent. In this example we have created a proxy of the dataserver so need to provide endpoint of DSS service.
Local Entry: Local entry mediator is used to put/attach any kind of wsdl, xquery, Javascript etc. For this example we have to pass dataservice wsdl as request structure needs to be remain same.
After modify the Synapse.xml, we can see a new service is added in the list of service in WSO2 ESB.
Call a data service from ESB WSO2
We have created an ‘EmployeeDataSource’ service in WSO2 DSS, Let’s call it in ESB.
As above we have already modify syapse.xml, just refresh the page, ‘DSS_EmployeeProxy’ service should be shown.
Click on try this service.
Click send button.
Data has been fetched through DSS Web Service.
This is the way, we use esb.
Now we need to analyses the synapse.xml and its main tag, elements and attributes.
We use some mediators in the esb to call the services.
We will analyze "Synapse.xml" in next blog..
Hello Shria ..would you like to help me out?
ReplyDeleteHi Abdul sorry for replying late.. I hope your issue is resolved by now but if you have any issue please comment me back. Thanks
ReplyDelete