Showing posts with label REST. Show all posts
Showing posts with label REST. Show all posts

Wednesday, October 5, 2016

REST in BPEL: invoking a RESTful service from BPEL

 Invoking a REST API with BPEL
Aim: To invoke a RESTful web service from a BPEL Service.
Oracle SOA does not provide native JSON capabilities, atleast with 11g. 12c improves with a JSON adapter (XML<->JSON) but still is not native. So, in this blog post we wil continue to stick with REST services returning XML data. We will see how to make calls to these services from a BPEL composite.
Steps:
The RESTful service which we are going to use in this POC is the Google Geocode API.
  1. Drag and Drop a HTTP Binding Service Adapter into the right swim lane.
  2. Configure the adapter as per the below screenshots:
Configuring the Binding:
Provide the request – response structures to the REST service in form of XSDs.
You might need to create these XSDs based on the XML returned from the service in case it is not provided to you. You should be able to use a tool like Eclipse/JDeveloper to achieve this.
  1. The HttpBinding is now ready. Integrate it with the BPEL code the same way one does for other partner links i.e use an invoke activity to call it with appropriate request/response variables.


Result:  We were able to call the Google Geocoding API through a BPEL process successfully.
Screenshots:


cid:image008.jpg@01CEC058.7BAAF6E0

cid:image009.jpg@01CEC058.7BAAF6E0

Friday, January 9, 2015

Invoking a RESTful webservice from OSB

For an introduction to REST and RESTful webservices, I recommend this great post on IBM DeveloperWorks.
http://www.ibm.com/developerworks/library/ws-restful/

In this post, we will see how we can invoke a web service based on REST from Oracle Service Bus.

We will be using the OpenWeather API, to get to know how REST invocations are simple,straight-forward yet effective and to know the weather in your city (or London), type this request in your browser:

http://api.openweathermap.org/data/2.5/weather?q=London&mode=xml.

We are gonna invoke this WS from OSB !!


1.) Create a business service as per the configuration in the screenshot below.

Note that the endpoint URI is just http://api.openweathermap.org/data/2.5/weather  and the http request method is GET.


2.)  Test the above business service by providing the input for REST web service in query-parameters under transport header tab in the test console.






This is how you add URL query parameters to an outgoing http call from OSB test console  ( The part after ? in the http URL are the set of parameters, http://api.openweathermap.org/data/2.5/weather?q=London&mode=xml )

Test this business service, you would see a response similar to:

3.) Now we would need to create a Proxy Service over this Business Service and will use the input from the Proxy Service to populate the query parameters dynamically at run-time. 
Create a simple Any XML proxy service, I choose any XML because this is just a tutorial and using any XML would save me the time and effort to create an XSD/WSDL.

I will be using the below xml as an input request to this Proxy Service.

<WeatherInfoRequest>
<City></City>
</WeatherInfoRequest>

Please note how I have omitted the other parameter "Mode" that takes a value of xml. 
I do not believe this is something that an end user would be concerned with and hence it will be hardcoded later somewhere.

Next, Add a route node to this proxy service. Inside the route node, add a routing action that routes to the Business Service we had created earlier.

Inside the request actions, add an action to insert the query parameters into the outbound context variable.
Note how the value of parameter "q" has been dynamically picked from the incoming xml.
Also, I have hardcoded the other parameter "mode" as "xml" because I don't believe that a user would be inputing this as mentioned earlier.

and that is it , we are all set to go ahead and test this Proxy Service.

4.) Test this Proxy Service from the OSB Test Console using an appropriate input, London is one such appropriate city input.

and there you go !! London looks fairly cold at this time of the year !!

In my upcoming post, I will share , how we can achieve the same from Oracle SOA BPEL. 
We will also be learning how can we create RESTlike (note the change from RESTful :) ) services in OSB itself.


Thanks for Reading and enjoy the New Year !!