TIBCO BW 5.X: Working with REST services

In this new post we come back to our older TIBCO BW 5.x to work with one the main elements in the Web nowadays: Rest Services. In some comments in this blog, some of you were asking about how to do things with REST services using TIBCO BW so, today, we are going to answer to some of these questions.

First of all, to be able to work with REST Service in the TIBCO BW 5.x we need to install the TIBCO ActiveMatrix BusinessWorks™ Plug-in for REST and JSON which is a separeted bundle (in TIBCO BW 6.X this capabilities are in the core product, so we won’t need any plugin).

Now when we open the TIBCO Designer we are going to see a new Palette called REST & JSON, as you can see here:

REST_1

With this palette you will be able to consume REST service and expose actual BW process like a REST service, so first of all we are going to work with the “consuming way”. We are going to use the API Geonames (api.geonames.org) to work with REST & JSON.

So, we are going to invoke this service. In this case we don’t have any WADL resource (the WADL is the REST equivalent to the WSDL in the SOAP Web Service) so we are going to do a  plain invocation using the “Invoke REST API” activity as you can see here:

REST_2

When you configure a Invoke REST API you could specifiy the following (relevant) options:

  • Method: You can specify the HTTP method you want to send your request with (GET, POST, PUT, DELETE..)
  • Reponse Type: You can specify the response format (JSON, XML, Binary…)
  • Authentication: You can specify the authentication of the REST Service, and this is an important feature because you can consume REST service with the following authentication  methods:
    • No Authentication.
    • Basic Authentication.
    • OAuth 1.0
    • OAuth 2.0 (This is the mainly option for secure REST API services like Twitter, Google, Facebook and so on)

After that, you must configure the parameters you are going to send in your request. In our test we are going to send three parameters (postalcode, username and country) as you can see here the configuration:

REST_3

After that we specify the URI in the input tab and we are ready to do the invocation to the service, but the service are going to response with a JSON string, similar to this:

 {"postalcodes":[{"adminCode2":"708","adminCode3":"70805","adminName3":"Breitenwang","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.7333333,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Breitenwang","lat":47.4833333},{"adminCode2":"708","adminCode3":"70806","adminName3":"Ehenbichl","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.7,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Ehenbichl","lat":47.4666667},{"adminCode2":"708","adminCode3":"70820","adminName3":"Lechaschau","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.7,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Lechaschau","lat":47.4833333},{"adminCode2":"708","adminCode3":"70822","adminName3":"Musau","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.6666667,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Musau","lat":47.5333333},{"adminCode2":"708","adminCode3":"70826","adminName3":"Pflach","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.7,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Oberletzen","lat":47.5166667},{"adminCode2":"708","adminCode3":"70827","adminName3":"Pinswang","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.6833333,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Oberpinswang","lat":47.5333333},{"adminCode2":"708","adminCode3":"70826","adminName3":"Pflach","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.7166667,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Pflach","lat":47.5166667},{"adminCode2":"708","adminCode3":"70827","adminName3":"Pinswang","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.6666667,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Pinswang","lat":47.5333333},{"adminCode2":"708","adminCode3":"70828","adminName3":"Reutte","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.7166667,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Reutte","lat":47.4833333},{"adminCode2":"708","adminCode3":"70826","adminName3":"Pflach","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.7,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Unterletzen","lat":47.5166667},{"adminCode2":"708","adminCode3":"70827","adminName3":"Pinswang","adminCode1":"07","adminName2":"Politischer Bezirk Reutte","lng":10.6666667,"countryCode":"AT","postalcode":"6600","adminName1":"Tirol","placeName":"Unterpinswang","lat":47.5333333}]}

So we have to parse the response so we can work with all these data in the following steps of our process. To do that we are going to use the Parse JSON activity from this REST & JSON Palette, and we only have to define the main structure of the data like you can see here:

REST_4

And now, yo could run your test process, and you have parsed the information returned by the REST service as you can see here:

REST_5

In following post we are going to explore the other capabilities of this plugin, like exposing REST service, consuming secured REST service and anything you want to ask about this plugin, so please, keep in touch with us so we can solve all your questions and doubts about the TIBCO software.

Advertisements

5 thoughts on “TIBCO BW 5.X: Working with REST services

  1. If i use TIBCO rest and Json pulgin in the designer level, Do i need to add this plug-in in tibco adminstration. Please help me on this.

    • You have to do one installation for any TIBCO_HOME you have. If you have your designer in the same TIBCO_HOME that your administrator, you’ll only need one installation. What do you want about compatiblity? With the BW versions? With the REST protocols? Please let us know and take a look to the readme file of the plugin at the docs.tibco.com!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s