Note: This post is based on SOA 12.1.3 release.
In this post, you will learn to expose Proxy Services as REST services. We will use Employees table and come up with REST API that can be used to perform CRUD operations.
This post assumes knowledge of DB connection pool setup and Pipelines.
Creating Business Service
Create the business service using DB Adapter with the help of following steps.














Click Finish and verify that business service has been created as shown below.

Refactor all the artifacts to BusinessService directory.

Now you can test business service alone to make sure that all operations are working fine as expected. You can refer to this post for detailed steps.
Creating REST Binding
We want our REST resource to support the following operations:
Resource
|
HTTP Verb
|
Resource URIs
|
Desription
|
Employees |
GET |
/Employees |
Get all employees |
|
GET |
/Employees/{employeeId} |
Get an employee represented by Employee ID. |
|
POST |
/Employees |
Create new employee |
|
PUT |
/Employees |
Update new employee |
|
DELETE |
/Employees/{employeeId} |
Delete an employee represented by Employee ID. |
In Service Bus 12c, REST proxy services convert REST native payload to SOAP before invoking a pipeline or split-join, while REST business services convert payload from SOAP to REST. That means, the internal interface is still based on WSDL, while the external business and proxy services expose REST endpoints. This will be evident in later steps as service bus creates both WADL and WSDL files and each resource is mapped to different operations defined in WSDL.
Drag REST binding into Proxy Services swim lane in Service Bus overview editor as shown below.


This brings up Create REST binding window. Give the name as shown below.

Click + icon for Resources to add new resource and click OK.

Similarly add another resource /Employees/{employeeId}. Now your resources should look like below.

Now you have to create the corresponding Operation Bindings which in turn creates WSDL with these operations.
Operation Bindings for resource /Employees:
Use the following steps to create GET mapping.



Here we are selecting both XML and JSON as we want our API to support both content types. Click on highlighted icon to define schema on fly representing the output payload. Enter file name and give directory name as ProxyService as shown below.

Click Next and choose file type as JSON.

Click Next and give Target namespace and Root element as shown below and you can use the following JSON payload sample.
{
“Employee” : [{
“employeeId”: “100”,
“firstName”: “fname”,
“lastName”: “lname”,
“email”: “fn@gmail.com”,
“phoneNumber”: “9848012345”,
“jobId”: “100”,
“salary”: “100”,
“commissionPct”: “100”,
“managerId”: “100”,
“departmentId”: “100”
},
{
“employeeId”: “101”,
“firstName”: “fname1”,
“lastName”: “lname1”,
“email”: “fn1@gmail.com”,
“phoneNumber”: “9848012345”,
“jobId”: “100”,
“salary”: “100”,
“commissionPct”: “100”,
“managerId”: “101”,
“departmentId”: “101”
}]
}

Click Next and verify the schema that gets generated.

Click Next and Finish and verify that schema URL is populated in Response tab.

Click OK and verify Operation Bindings are populated as shown below.

Use the following steps to create POST mapping by reusing existing schema.






Similarly, finish mapping for PUT and use operation name as updateEmployee. Now your Create REST binding window should look like below.

Click OK. You will observe that Proxy Service, WADL and WSDL have been created as expected.

You will also observe errors, as XSD file is created in ProxyService folder whereas WADL and WSDL got created in Resources folder. So open WADL and WSDL files and modify the XSD reference as shown below to resolve errors.


Operation Bindings for resource /Employees/{employeeId}:
You should reuse the schema created in above steps for this resource as well.
Now in Service Bus overview editor, right click EmployeeService and select Edit REST as shown below.

Use the following steps to create GET mapping.


You can leave schema for request as it is so that it will be defaulted by the wizard.



Click OK and your Update Service window should look like below.

Similarly finish DELETE method by using operation name as deleteEmployee and now your Update Service window should look like below.

Click OK and observe the WADL and WSDL files that got updated with your new operation bindings. If you observe that WADL is not updated just do refresh as shown below.

WADL:

WSDL:

With this, you have finished the REST interface that is exposed to consumers.
Creating Pipeline:
Create new pipeline EmployeePipeline using EmployeeService.wsdl as shown below.


Connect EmployeeServcie proxy service with EmployeePipeline in Service Bus overview editor as shown below.

We will not discuss much about finishing the message flow in pipeline as it’s nothing different from regular scenario. You can find the Service Bus project here i.e. used for demonstration purpose in this post.
Testing:
In test console, you can observe that Accept http header shows both application/xml and application/json i.e. now your REST service supports both xml and json data formats.
GET With application/xml:


GET With application/json:


POST With application/xml:


POST With application/json:


You can observe that both records have been inserted as expected.

PUT With application/xml:


PUT With application/json:


You can observe that both records have been updated as expected.

Resource /Employees/{employeeId}:
GET With application/xml:


GET With application/json:


DELETE With application/xml:


DELETE With application/json:


You can observe that both records have been deleted as expected.

If you want to expose SOAP interface as well, then you just need to create another Proxy Service and join EmployeePipeline as shown below.

Notes:
- We did not talk about fault handling specific details here.
- It’s always recommended not to do blind GET as we may see performance issues when large number of records are there.
- As an exercise, you can come up with resource emulating QBE on db.
References:
https://docs.oracle.com/middleware/1213/osb/develop/GUID-C346DF7D-041D-4E10-BE1C-451F50719106.htm#OSBDV88210
Like this:
Like Loading...