Tuesday, August 13, 2013

How to call Data Service in ESB WSO2

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.


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:
└── 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"/>
            <sequence name="DSS_EmployeeProxy_IN">
        <log level="full"/>
            <endpoint key="DSS_EmployeeProxy_EPR"/>
             <sequence name="DSS_EmployeeProxy_OUT">
        <log level="full"/>
            <localEntry key="DSS_EmployeeProxy_wsdl" src="file:repository/conf/employee/EmployeeDataService.wsdl"/>
            <endpoint name="DSS_EmployeeProxy_EPR">
        <address uri="">
            <sequence name="CommonFaultHandler">
        <log level="custom">
            <property name="MESSAGE" value="Executing default &quot;fault&quot; sequence"/>
            <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
        <header name="To" action="remove"/>
    <!-- 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 -->

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..