Sunday 15 October 2017

There are two types of web services. SOAP and REST web services. We usually deal with SOAP web services in Oracle SOA but we can also create RESTful web services in SOA.

RESTful web services are built to work best on the Web. Representational State Transfer (REST) is an architectural style. In REST data can be transmitted over a standardized interface (such as HTTP).


This post shows how we can create RESTful web service in Oracle SOA. Follow below steps to create it.
We will use below schema for this post.




First create one SOA project. In composite.xml file drag “HTTP Binding” adapter and start configure it.





Choose “service” from type drop-down list.

Choose request and response element from your schema.


Once you create HTTP binding adapter, drag a BPEL process to composite.xml file.




Wire your BPEL process with HTTP adapter.




 Inside BPEL process, add receive activity and link it to HTTP adapter to receive the request.



Add reply activity and link it to HTTP adapter to send the response back.


Deploy your composite.


You can test your composite using below URL.

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



 Testing Results







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.

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



    Above element will add as a child of <http:query-parameters> element.



    Do it same for another query parameter.

    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

    No comments:

    Post a Comment