In this post, I will show you how we can call RESTful service from Oracle Service Bus.
We will use below RESTful web service which we created in previous post.
To create project in OSB first we need to create a session and add new OSB project. Add required project folders to this project. Your project should look like below.
Go to business folder and start with Business service creation, which in turn call our RESTful service. Give your business service a name and choose “Message Service” as Service Type. Choose Request Message Type as “None” and Response Message Type as “Text”.
Choose “http” from protocol drop-down list and add RESTful web service endpoint to Endpoint URI. Make sure you don’t add full URI, don’t include parameter when you mention URI here. Click on “Add” to add your service URI.
Choose HTTP Request Method as “GET” from drop-down list.
Accept default and save your Business service. Your Business service creation is complete.
You can test your business service to check whether it successfully call RESTful service. Make sure you activate your session before testing your business service.
We use below request message to test our Business Service.
Below is the response from RESTful service to Business Service.
Now we will create a proxy service which will call above created business service and pass required query parameters to business service.
Go to proxy folder and create a proxy service, name your proxy service and choose “Business Service” as Service Type. Browse to already created business service and click next.
Accept defaults and complete your proxy service creation. Now we need to pass required query parameters to business service which in turn uses these parameters to call RESTful web service.
We use Insert activity to pass required parameters to business service.
To add required insert activates go to proxy service message flow and add Insert activity to it.
Click on <Xpath> link and choose “transport/request” element as we will add “http-method” as a child of outbound transport request.
First Insert activity should look like below.
Add another Insert activity, in this Insert activity we will add query-parameters element to outbound request message. Click on expression link and add below text to it.
Click on <Xpath> link and choose “transport/request” element as we will add “query-parameters” as a child of outbound transport request.
Now we need to add two query parameters which are required to call that RESTful service. Add first parameters by adding another Insert activity. Click on expression link and add bellow text to it.
<http:parameter name="operationName" value="Request-Response"/>
Above element will add as a child of <http:query-parameters> element.
Do it same for another query parameter.
Activate your session and test your proxy service.
You can see below outbound message and clearly see all the required information in this message which is required to call RESTful service.
When you test your proxy service, you may receive below error message.
To resolve this error, we need to add proper encoding, to do that we need to add another Insert activity to message flow of proxy service.
Above element will be added as child of outbound “transport/request” element.
Below is your final message flow.
Sample code can be downloaded from here.