Showing posts with label DSS. Show all posts
Showing posts with label DSS. Show all posts

Monday, October 16, 2017

Create a dynamic/filtered query service in WSO2 DSS.



Sometimes we have requirement in which we have to call a database query at run time. For example, we have an employee table and need to get details from this table with some condition like “where emp_last_name=? and address=?”. In above scenario if we don’t know the how many condition cab be there at run time, DSS filtered query can be used.


DSS file:


<data name="DynamicDS" transports="http https local">
   <config enableOData="false" id="DynamicQueryEmp">
      <property name="driverClassName">com.mysql.jdbc.Driver</property>
      <property name="url">jdbc:mysql://localhost:3306/emp</property>
      <property name="username">root</property>
      <property name="password">root</property>
   </config>
   <query id="DynaminQuery" useConfig="DynamicQueryEmp">
      <sql>select id, name, address from emp :filterQuery</sql>
      <result defaultNamespace="http://shriwithjava.blogspot.co.nz/" element="employees" rowName="employee">
         <element column="id" name="id" xsdType="xs:string"/>
         <element column="name" name="name" xsdType="xs:string"/>
         <element column="address" name="address" xsdType="xs:string"/>
      </result>
      <param name="filterQuery" sqlType="QUERY_STRING"/>
   </query>
   <operation name="getEmployees">
      <call-query href="DynaminQuery">
         <with-param name="filterQuery" query-param="filterQuery"/>
      </call-query>
   </operation>
</data> 




In this DSS file we can use any database condition and pass it to DSS as parameter




Monday, August 1, 2016

How to use Clone Mediator in WSO2 ESB

Clone mediator is used to send same massage to multiple endpoints. It basically clone same message to multiple message based on our requirement and send it to multiple endpoints. We can aggregate the response which we get from the multiple endpoints and show as one response.

Requirement:

Suppose there is a requirement where we have to get the entire IT employee details who all works overseas. We have different databases and different places and each database has employee records. We have only one input parameter which is department, all I need is IT employee details.

Solution:

I have created 3 data services, first provides Indian employee detail, second provide USA employee details and 3rd provides New Zealand employee details. I have created same format DSS with same namespace with one input parameter and 4 output parameter in one employee list and response can have multiple employee list.


DSS:
<data name="EmployeeDetailsNZ" enableBatchRequests="false" enableBoxcarring="false" serviceStatus="active">
   <description>This provides Employee details</description>
   <config id="EMPDS">
      <property name="org.wso2.ws.dataservice.driver">oracle.jdbc.driver.OracleDriver</property>
      <property name="org.wso2.ws.dataservice.protocol">jdbc:oracle:thin:SYSTEM/SYSTEM@localhost:1521/xe</property>
      <property name="org.wso2.ws.dataservice.user">SYSTEM</property>
      <property name="org.wso2.ws.dataservice.password">SYSTEM</property>
      <property name="org.wso2.ws.dataservice.minpoolsize"></property>
      <property name="org.wso2.ws.dataservice.maxpoolsize"></property>
      <property name="org.wso2.ws.dataservice.validation_query"></property>
   </config>
   <query id="EmpDetailsQuery" useConfig="EMPDS">
      <sql>select * from EMP_DETAILS_NZ where DEPARTMENT_V=?</sql>
      <result element="EmployeeDetails" rowName="EmployeeData" defaultNamespace="http://shriwithjava.blogspot.co.nz/">
         <element name="EmployeeId" column="EMP_ID_N" xsdType="xs:string" />
   <element name="EmployeeName" column="EMP_NAME_V" xsdType="xs:string" />
   <element name="EmployeeAddress" column="EMP_ADD_V" xsdType="xs:string" />
   <element name="Department" column="DEPARTMENT_V" xsdType="xs:string" />
   </result>
      <param name="Department" paramType="SCALAR" sqlType="STRING" type="IN" />
   
   </query>
   <operation name="getEmployeeDetails">
      <description></description>
      <call-query href="EmpDetailsQuery">
         <with-param name="Department" query-param="Department" />
   
      </call-query>
   </operation>
</data>

DSS request and response format:

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:shr="http://shriwithjava.blogspot.co.nz/">
   <soapenv:Header/>
   <soapenv:Body>
      <shr:getEmployeeDetails>
         <shr:Department>IT</shr:Department>
      </shr:getEmployeeDetails>
   </soapenv:Body>
</soapenv:Envelope>

Response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <EmployeeDetails xmlns="http://shriwithjava.blogspot.co.nz/">
         <EmployeeData>
            <EmployeeId>201</EmployeeId>
            <EmployeeName>Shri</EmployeeName>
            <EmployeeAddress>Auckland</EmployeeAddress>
            <Department>IT</Department>
         </EmployeeData>
         <EmployeeData>
            <EmployeeId>202</EmployeeId>
            <EmployeeName>Bhajan</EmployeeName>
            <EmployeeAddress>Wellington</EmployeeAddress>
            <Department>IT</Department>
         </EmployeeData>
      </EmployeeDetails>
   </soapenv:Body>
</soapenv:Envelope>



ESB Changes:

I have created a service which will get all the details of the overseas employee for different department. I will call all the endpoints (Indian, USA and New Zealand employee details) and aggregate the response into one. I have to use same input and that will be cloned for each endpoint from the clone mediator.

Synapse Code:

<definitions>
<proxy name="OverseasEmpDetailsProxy" transports="http" startOnLoad="true" trace="disable" statistics="enable">
   <target inSequence="OverseasEmpDetails_IN" outSequence="OverseasEmpDetails_OUT" faultSequence="CommonFaultHandler"/>
   <publishWSDL key="OverseasEmpDetails_wsdl"/>
</proxy>
<localEntry key="OverseasEmpDetails_wsdl" src="file:repository/conf/employee/OverseaseEmployee.wsdl"/>
 
<sequence name="OverseasEmpDetails_IN">
 <clone>
  <target>
   <endpoint key="NZEmployeeDetails_EPR"/>
  </target>
  <target>
   <endpoint key="INDEmployeeDetails_EPR"/>
  </target>
  <target>
   <endpoint key="USAEmployeeDetails_EPR"/>
  </target>
 </clone>
</sequence>
 
<sequence name="OverseasEmpDetails_OUT">
   <aggregate>
  <completeCondition>
   <messageCount min="-1" max="-1"/>
  </completeCondition>
  <onComplete xmlns:shr="http://shriwithjava.blogspot.co.nz/" expression="//shr:EmployeeDetails/shr:EmployeeData">
   <send/>
  </onComplete>
 </aggregate>
</sequence>
 
 <endpoint name="NZEmployeeDetails_EPR">
 <address uri="http://localhost:9763/services/EmployeeDetailsNZ">
  <timeout>
   <duration>10000</duration>
   <responseAction>fault</responseAction>
  </timeout>
  <suspendOnFailure>
   <errorCodes>101500,101501,101506,101507,101508</errorCodes>
   <progressionFactor>0.0</progressionFactor>
  </suspendOnFailure>
  <markForSuspension>
   <errorCodes>101504,101505</errorCodes>
  </markForSuspension>
 </address>
</endpoint>
 <endpoint name="INDEmployeeDetails_EPR">
 <address uri="http://localhost:9763/services/EmployeeDetailsIndia">
  <timeout>
   <duration>10000</duration>
   <responseAction>fault</responseAction>
  </timeout>
  <suspendOnFailure>
   <errorCodes>101500,101501,101506,101507,101508</errorCodes>
   <progressionFactor>0.0</progressionFactor>
  </suspendOnFailure>
  <markForSuspension>
   <errorCodes>101504,101505</errorCodes>
  </markForSuspension>
 </address>
</endpoint>
 <endpoint name="USAEmployeeDetails_EPR">
 <address uri="http://localhost:9763/services/EmployeeDetailsUSA">
  <timeout>
   <duration>10000</duration>
   <responseAction>fault</responseAction>
  </timeout>
  <suspendOnFailure>
   <errorCodes>101500,101501,101506,101507,101508</errorCodes>
   <progressionFactor>0.0</progressionFactor>
  </suspendOnFailure>
  <markForSuspension>
   <errorCodes>101504,101505</errorCodes>
  </markForSuspension>
 </address>
</endpoint>
 
<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')"/>
 </log>
 <header name="To" action="remove"/>
 <drop/>
</sequence>
 
 
</definitions>


Restart the ESB and load the WSDL in SOAP UI results will look like:

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:shr="http://shriwithjava.blogspot.co.nz/">
   <soapenv:Header/>
   <soapenv:Body>
      <shr:getEmployeeDetails>
         <shr:Department>IT</shr:Department>
      </shr:getEmployeeDetails>
   </soapenv:Body>
</soapenv:Envelope>


Response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <EmployeeDetails xmlns="http://shriwithjava.blogspot.co.nz/">
         <EmployeeData>
            <EmployeeId>201</EmployeeId>
            <EmployeeName>Shri</EmployeeName>
            <EmployeeAddress>Auckland</EmployeeAddress>
            <Department>IT</Department>
         </EmployeeData>
         <EmployeeData>
            <EmployeeId>202</EmployeeId>
            <EmployeeName>Bhajan</EmployeeName>
            <EmployeeAddress>Wellington</EmployeeAddress>
            <Department>IT</Department>
         </EmployeeData>
         <EmployeeData>
            <EmployeeId>004</EmployeeId>
            <EmployeeName>Viru</EmployeeName>
            <EmployeeAddress>Kanpur</EmployeeAddress>
            <Department>IT</Department>
         </EmployeeData>
         <EmployeeData>
            <EmployeeId>111</EmployeeId>
            <EmployeeName>Tahseen</EmployeeName>
            <EmployeeAddress>New York</EmployeeAddress>
            <Department>IT</Department>
         </EmployeeData>
         <EmployeeData>
            <EmployeeId>113</EmployeeId>
            <EmployeeName>JD</EmployeeName>
            <EmployeeAddress>Washington</EmployeeAddress>
            <Department>IT</Department>
         </EmployeeData>
      </EmployeeDetails>
   </soapenv:Body>
</soapenv:Envelope>

You can see the response from different service have been merged into one and we only sent a single request with a department parameter.

Wednesday, January 20, 2016

How to call a WSO2 web service from Stored Procedure


I am using oracle database for calling a web service created in WSO2. You can call any web service from the oracle database or procedure. Oracle provides UTL_HTTP package, which is used to make HTTP call out from the procedure or SQL query.  You can use it to access the data on the internet.

Important parameter:

UTL_HTTP.BEGIN_REQUEST: This is used to send request in URL up to 32767 bytes.
UTL_HTTP.SET_HEADER: This is used to set request header of the request.
UTL_HTTP.READ_TEXT:  This is used to read response in text format and you can then extract values from the response.

Example:
I have created a web service in DSS which fetch the unique transaction number from a sequence created in database. On the top of it I have created wrapper in ESB. Now I will create a stored procedure and try to call this ESB service from it.

Stored Procedure:
 create or replace PROCEDURE "GET_UNIQUE_NUMBER" (  
   Result_Desc OUT VARCHAR2,  
   Result_Value OUT VARCHAR2)  
 IS  
  HTTP_REQ UTL_HTTP.REQ;  
  HTTP_RESP UTL_HTTP.RESP;  
  L_ENDPOINT VARCHAR2(100);  
  L_ENV    VARCHAR2(32767);  
  L_WS_RESP  VARCHAR2(32767);  
  L_START_POS NUMBER;  
  L_END_POS  NUMBER;  
 BEGIN  
  L_ENV :=  
  '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://services.nzc/xsd">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <xsd:getUniqueNumber>  
      <xsd:request>  
       <xsd:channelID>DUMMY</xsd:channelID>  
       <xsd:dateTimeStamp>DUMMY</xsd:dateTimeStamp>  
      </xsd:request>  
    </xsd:getUniqueNumber >  
   </soapenv:Body>  
 </soapenv:Envelope>';  
  L_ENDPOINT:='http://localhost:8280/services/GetUniqueNumberProxy';  
  UTL_HTTP.SET_DETAILED_EXCP_SUPPORT(TRUE);  
  UTL_HTTP.SET_PERSISTENT_CONN_SUPPORT (TRUE);  
  HTTP_REQ:= UTL_HTTP.BEGIN_REQUEST(L_ENDPOINT,'POST', 'HTTP/1.1');  
  UTL_HTTP.SET_HEADER (HTTP_REQ, 'Content-Type', 'text/xml' );  
  UTL_HTTP.SET_HEADER (HTTP_REQ, 'charset', 'UTF-8' );  
  UTL_HTTP.SET_HEADER (HTTP_REQ, 'Content-Length', LENGTH (L_ENV) );  
  UTL_HTTP.SET_HEADER (HTTP_REQ, 'SOAPAction', '' );  
  UTL_HTTP.WRITE_TEXT (HTTP_REQ,L_ENV);  
  HTTP_RESP := UTL_HTTP.GET_RESPONSE (HTTP_REQ);  
  UTL_HTTP.READ_TEXT (HTTP_RESP,L_WS_RESP);  
  UTL_HTTP.END_RESPONSE (HTTP_RESP);  
  L_WS_RESP:= REPLACE(SRCSTR => L_WS_RESP, OLDSUB => ' xmlns=""', NEWSUB => '');  
  L_START_POS   := INSTR(L_WS_RESP, '<ns:uniqueNumber')+LENGTH('<ns: uniqueNumber'>');  
  L_END_POS    := INSTR(L_WS_RESP, '</ns: uniqueNumber'>');  
  Result_Value := SUBSTR(L_WS_RESP, L_START_POS, (L_END_POS - L_START_POS));  
   DBMS_OUTPUT.PUT_LINE('UniquerNumber : ' || Result_Value);  
   Result_Desc     := 'Success';  
 EXCEPTION  
 WHEN OTHERS THEN  
  Result_Desc     := 'Unknown Issue Found';  
  Result_Value:='0000';  
  ROLLBACK;  
 END GET_UNIQUE_NUMBER;  



Result:
Connecting to the database <Schema_Name>.
UniqueNumber : 201601211159403411
Process exited.
Disconnecting from the database <Schema_Name>.

Screenshots:




Sunday, December 20, 2015

How to use Oracle Ref Cursor in WSO2 DSS

Ref cursor in oracle is a data type and WSO2 DSS support this data type to be called. In this blog we will see that how ref cursor is called from DSS, for this I have created a table in oracle which holds the employee details and also created a stored procedure having a cursor into that and will get the employee details based on an input employee id.

Table: EMP_DETAILS



Now insert some data into this table so that from DSS service we can get employee detail based on employee id.


In this table I have inserted 3 records as above and now create a stored procedure which has ref cursor.

Stored Procedure: GETEMPLOYEE


create or replace PROCEDURE GETEMPLOYEE(
EMP_ID  IN VARCHAR2,
RESULT_CODE  OUT VARCHAR2,
EMPLOYEE_DETAILS_RESULT OUT SYS_REFCURSOR
) AS

BEGIN
  OPEN EMPLOYEE_DETAILS_RESULT FOR 
  SELECT * FROM EMP_DETAILS WHERE EMP_ID_N=EMP_ID;
  RESULT_CODE:='0';
  EXCEPTION WHEN OTHERS THEN
  RESULT_CODE:='-1';
END GETEMPLOYEE;


This procedure will be called from the DSS server. I am putting only DSS (.dbs) file code in below section. If you want to complete this section from the UI you can follow this blog which has the details that how DSS is created through UI.

DSS (.dbs) file:

 <data name="EmployeeDatailsService" enableBatchRequests="false" enableBoxcarring="false" serviceStatus="active">  
   <config id="EmployeeDS">  
    <property name="org.wso2.ws.dataservice.driver">oracle.jdbc.driver.OracleDriver</property>  
    <property name="org.wso2.ws.dataservice.protocol">jdbc:oracle:thin:SYSTEM/SYSTEM@localhost:1521/xe</property>  
    <property name="org.wso2.ws.dataservice.user">SYSTEM</property>  
    <property name="org.wso2.ws.dataservice.password">SYSTEM</property>  
    <property name="org.wso2.ws.dataservice.minpoolsize"></property>  
    <property name="org.wso2.ws.dataservice.maxpoolsize"></property>  
    <property name="org.wso2.ws.dataservice.validation_query"></property>  
   </config>  
   <query id="EmployeeDatailsQuery" useConfig="EmployeeDS">  
    <sql>call GETEMPLOYEE(?,?,?)</sql>  
        <result element="EmployeesDetails" defaultNamespace="http://shriwithjava.blogspot.co.nz/">    
            <element name="ResultCode" column="RESULT_CODE" xsdType="xs:string" />      
      <element name="EmpID" column="EMP_ID_N" xsdType="xs:string" />       
      <element name="Name" column="EMP_NAME_V" xsdType="xs:string" />       
      <element name="Address" column="EMP_ADD_V" xsdType="xs:string" />     
            <element name="Country" column="COUNTRY_V" xsdType="xs:string" />   
    </result>    
        <param name="EMP_ID" paramType="SCALAR" sqlType="STRING" type="IN" ordinal="1" />   
    <param name="RESULT_CODE" paramType="SCALAR" sqlType="STRING" type="OUT" ordinal="2" />   
       <param name="EMPLOYEE_DETAILS_RESULT" sqlType="ORACLE_REF_CURSOR" type="OUT" ordinal="3"/>  
   </query>  
   <operation name="getEmployeeDetails">  
    <description></description>  
    <call-query href="EmployeeDatailsQuery" >  
           <with-param name="EMP_ID" query-param="EMP_ID" />   
           </call-query>  
   </operation>  
 </data> 

Testing from Soap UI:

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:shr="http://shriwithjava.blogspot.co.nz/">
   <soapenv:Header/>
   <soapenv:Body>
      <shr:getEmployeeDetails>
         <shr:EMP_ID>111</shr:EMP_ID>
      </shr:getEmployeeDetails>
   </soapenv:Body>
</soapenv:Envelope>

Response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <EmployeesDetails xmlns="http://shriwithjava.blogspot.co.nz/">
         <ResultCode>0</ResultCode>
         <EmpID>111</EmpID>
         <Name>SHRI</Name>
         <Address>RAEBARELI</Address>
         <Country>INDIA</Country>
      </EmployeesDetails>
   </soapenv:Body>
</soapenv:Envelope>




Sunday, August 9, 2015

How to change default port number of WSO2 ESB, DSS and BPS

WSO2 product ESB, DSS and BPS by default runs on 9443 port. It is fine if all servers are hosted in different machine but if you have to run locally in one system then port number change is required.

For this Example we are using below versions:

  • ESB: 4.0.3
  • BPS: 2.1.2
  • DSS: 2.5.1

 To change port number in ESB go to wso2esb-4.0.3\repository\conf\carbon.xml under the “ServletTransports” tag you can change your setting.

  <!-- Override the ports defined in mgt-transports.xml -->
        <ServletTransports>
            <HTTPS>9443</HTTPS>
            <HTTP>9773</HTTP>
        </ServletTransports>


When you start the server the port number shows 9443.
Now change port number in “carbon.xml” file with new 9453 port number and again restart your server.

<!-- Override the ports defined in mgt-transports.xml -->
        <ServletTransports>
            <HTTPS>9453</HTTPS>
            <HTTP>9773</HTTP>
        </ServletTransports>

You can see this in logs as well.


Now if you open this highlighted URL in browser the below screen will come and showing that ESB is now running in 9453 port number.



Change port in BPS:

Change in “carbon.xml” file, located in wso2bps-2.1.2\repository\conf\mgt-transports.xml

   <!-- ${Ports.ServletTransports.HTTPS} is defined in the Ports section of the carbon.xml -->
        <parameter name="port">9453</parameter>



Change port in DSS:

Change in “mgt-transports.xml” file located in wso2dataservices-2.5.1\repository\conf folder.

<transport name="https" class="org.wso2.carbon.server.transports.http.HttpsTransport">
        <parameter name="port">9453</parameter>



If there is any requirement like you have to run above 3 servers at a time in your local machine then port number should be different like 9443, 9453 and 9463 or any port number you like.

Monday, July 27, 2015

How to create Data Source in WSO2 DSS

In this blog we will see hot to create a data source in DSS and will use the same in one data service.

Data source is just a database connection to fetch the data from the database, but we keep it in a common place and keep using this from data service so that if in future if any change is required then no need to go again and again in each data service and change it but good option to change in one place and it will reflect in all the data service whichever is using this data source. This gives the flexibility to service to enable data stored in several of data storage, Here we will only talk about RDBMS data source.

RDBMS data sources are used to service enable data from a relational database.


Steps to create Data Source:



Click on configuration on left panel above sheen will come.


Click on Data Sources icon to create new Data Source.


Fill the details as required, here we are creating data source for MySql database.


Once you fill all the necessary information then check the connection by clicking “Test Connection” if everything is configured properly a screen will popup saying “Connection is healthy”.


This is the last step just click on the save button to create this data source. It will be added in above screen.

Example:

 <data name="EmployeeDataService" enableBatchRequests="false" enableBoxcarring="false" serviceStatus="active">    
   <config id="mySqlDataSource">     
   <property name="carbon_datasource_name">mySqlDataSource</property>  
   </config>    
   <query id="DataQueryEmp" useConfig="mySqlDataSource">     
    <sql>select EMP_ID, EMP_NAME, EMP_ADDRESS from emp_table where EMP_ID=?</sql>     
    <result element="employees" rowName="employee" defaultNamespace="http://shriwithjava.blogspot.co.nz/">       
      <element name="id" column="EMP_ID" xsdType="xs:string" />       
      <element name="name" column="EMP_NAME" xsdType="xs:string" />       
      <element name="address" column="EMP_ADDRESS" xsdType="xs:string" />     
    </result>    
       <param name="empId" paramType="SCALAR" sqlType="STRING" type="IN" />    
   </query>    
   <operation name="getEmployees">     
    <description></description>     
    <call-query href="DataQueryEmp" >  
 <with-param name="empId" query-param="EmpId" />   
 </call-query>      
   </operation>  
 </data>  

Tuesday, July 21, 2015

How to apply Caching in WSO2 DSS

There is very easy way to apply caching in WSO2 DSS using console UI. Whenever we create a data service which interacts with the database and if we realize that database is not being change very frequently then Caching can be used. We have to set caching time in this UI configuration by which request will not go to database each time (within the caching time), this way we can optimize our solution and reduce the response time of the service as well.

In this blog we will set a caching in a data service which has been created with Mysql database which fetches the employee data from the database. If you have to see that how this service is created then go to my first DSS Blog.





Here is the list of different service but we have to put caching only in empDetail data service. To apply caching click on this service, it will open below page.




Again click on this empDetail service, it will redirect to you below page.



In this page there are different option but you have to choose Response Caching option, once you click this you will be rediredted to below page.


There is a drop down button in which you have to choose ‘Yes’ to enable cache. After selecting YES, it will go to below page.


In this page basically, you have to put caching time and maximum caching size on number and other details as well. You can set this time to 1 hour, 1 day as required.

Click on finish button to enable caching.


One caching is enabled above page will pop up with successful message.
If you restart the server then the first hit will go to the database and first hit’s data will be cached and DSS will be reusing this data until caching time gets expired then again it follow the same process.

Make sure whenever you apply caching, restart your DSS server for the best practice.





Monday, August 12, 2013

Call Stored Procedure from WSO2 DSS



We have already created a Data Service for the mysql database. Now we will use Stored Procedure in Oracle and call them in our data service.
Let’s first create database and Stored Procedure.


Create a database, in this example I have used database name is “shri”.
Enter Username/Password – shri/shri
Create a table with the name of “EMPLOYEE”


If you want to insert some values in this table, then use insert command.


Now in this service we have to use Stored Procedure, so let’s create a stored procedure with the name of “EMP_INFO_INSERT”.


Click “OK” button.
And write the stored procedure for insert values in employee table as given below.

create or replace
PROCEDURE EMP_INFO_INSERT(
               p_emp_id IN EMPLOYEE.EMP_ID%TYPE,
               p_emp_name IN EMPLOYEE.EMP_NAME%TYPE,
               p_emp_add IN EMPLOYEE.EMP_ADD%TYPE,
               p_department_id IN EMPLOYEE.DEPARTMENT_ID%TYPE,
     p_designation_id IN EMPLOYEE.DESIGNATION_ID%type)
IS

BEGIN

  INSERT INTO employee (EMP_ID, "EMP_NAME", "EMP_ADD", DEPARTMENT_ID, DESIGNATION_ID )
  VALUES (p_emp_id, p_emp_name,p_emp_add, p_department_id, p_designation_id);

  COMMIT;
 END EMP_INFO_INSERT;




Compile it.
We are done with the database end, now need to create a service to call this stored procedure at DSS end.

DSS:-
Start the server from below location (double click on wso2server.bat file)
D:\...\wso2dataservices-2.5.1\bin\wso2server.bat
Server will be running on below address.
https://10.167.19.32:9443/carbon/admin/login.jsp





Enter Username/Password – admin/admin


You can see all the WebServices on clicking the of List link under the service tab.


Let’s create a new DSS service, click on create link under dataservice.
Enter “StoredProcedureExample” in dataservice textbox, click next.




Click Next.

In next page we need to add a Data Source.
Fill all required details as given below.
dataSource Id – OracleSPExample
DataSource Type – RDBMS
Database Engine - Generic
Driver Class - oracle.jdbc.driver.OracleDriver
JDBC URL - jdbc:oracle:thin:shri/shri@localhost:1521/xe
User Name – shri
Password - shri



Click on “Test Connection” Button, if connection is ok, will give successfully connected popup message otherwise give an error.


Click on “Save” button.
OracleSPExample data source is created. You can also edit or delete this data source.




If we need to create or add more data Source, repeat the above process again otherwise click “Next” button.
In next Page we have to add query which will fetch records from the database.

In this Page fill all required fields.
Query Id – selectEmployees
Data Source – OracleSPExample (It comes after creating data source in previous page)
SQl - select * from employee
Now we need give input or output mapping.
When we have to take output according to given input that we need to give here. In this example we are not giving any input criteria, just getting the output of the select query.


We have to define only output mapping here

In the “Result (Output Mapping)” block define below property.

Grouped by element – employees
Row name – employee
Row namespace - http://test.org



Click ‘Add Output Mapping‘.
Map all elements as defined in database table.
First element is added (EMP_ID).



EMP_NAME is added


Add EMP_ADD in output mapping


DEPARTMENT_ID is added


Last element in table is DESIGNATION_ID click add button to add this element.



Click ‘Main Configuration’ button, click yes when popup is open.



Result (Output Mapping) will look like this.


Click Save button.





selectEmployees query has been added. Let’s add one more query to call stored procedure.

In this Page fill all required fields.
Query Id – employees
Data Source – OracleSPExample (It comes after creating data source in previous page)
SQl - call EMP_INFO_INSERT(?,?,?,?,?)
Now we need give input or output mapping.
When we have to take output according to given input that we need to give here. In this example we are passing input elements to add data in the table



Click Add New Input Mapping button



In above image map EMP_ID, it is numeric type in database so sql type ‘Numeric’ has been selected
Click add button

Map EMP_NAME



Click add button

Next is EMP_ADD




Click add button

DEPARTMENT_ID has been mapped


Click add button
Last is designation_id 


Click Add button

Click main configuration button, click yes when popup is opened.


Input mapping will look like this (as below image)


On Clicking Save button below page should be shown.


Click Next button.


Click ‘Add New Operation’



Give addEmployee in Operation Name
Select Query Id – employees
Click Save button
Next page should be shown as below.



here we need to add one more operation
One for the adding record in the database (addEmployee)
Second is ‘selectEmployee’ which will fetch record from database.





Give Operation Name is selectEmployee
queryId – selectEmployees
click save button

Next page would look like this.



Click finish.
New service must be show in service list with the name of ‘StoredProcedureExample’.



Click ‘try this service’.


Click selectEmployee.


Whole record has been fetched from the database.


Now click addEmployee Operation.



Enter fields


Enter values and click ‘addEmployee’ button. Inserted record will be saved in the database, to show this value you can perform selectEmployee button again.