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 !!

2 comments:

  1. Can you please share how to pass path parameter dynamically in URI using OSB .

    ReplyDelete