Friday, January 10, 2014

In my previous posts, I discussed about how to create RESTful web service and how to call RESTful service from SOA.

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.

http://localhost:8001/soa-infra/services/default/RESTfulService/http_Client?input=test&operationName=Request-Response

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.

CallRESTfulService


    • business
    • proxy
    • resources


    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.


    First Insert action will add “http-method” to outbound request.
    To do that click on expression link of Insert activity and add below text to it.

    <http:http-method>GET</http:http-method>
    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.

    <http:query-parameters/>
    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.

    <http:parameter name="input" value="test"/>
    Your proxy service message flow will have total 4 insert activities now.

    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.



    Again test your proxy service.

    Testing Results



    Sample code can be downloaded from here.


    5 comments :

    1. It is truly a great and helpful piece of information.
      I am satisfied that you simply shared this useful information with us.
      Please stay us informed like this. Thanks for sharing. I know something information, to know you can click here
      Test and Tag brisbane
      Electrical Testing Services brisbane

      ReplyDelete
    2. This is an interesting post but it doesn't a rest call. A rest call must look like GET http:///resource (ex. GET http:///productID. So the business service URI must be dynamically modified.
      Best regards.

      ReplyDelete
    3. Hi,Thanks a lot for the Article. Do you have any example which shows how to pass data for POST method from OSB to a Rest Service? We want use OSB as a pass through proxy for a rest service. We are unable to pass the post data to the rest service from OSB. Can you please give us some idea on that?

      ReplyDelete
    4. This article is just what I needed - Thanks a lot , it was very helpful to me

      ReplyDelete
    5. im looking for same like anonymous with post of 28 of september

      ReplyDelete