Normally when we create our process we include an input protocol to comunicate our process with the outside world. We can use a lot of technologies to do this expose to the outside, but normally the usual choices are HTTP and JMS. And when we talk about HTTP normally we are talking about WebService using HTTP/SOAP as the protocol.
But, nowadays it’s more common to have to deal with REST interfaces and also to expose a REST interface as a default option or as a second option (device oriented in most cases). Ok, so in this post we are going to see the main stepts to create an API REST in TIBCO BW 5.X.
First things first, The REST Palette (formaly is the REST & JSON Palette) is not included with the standard installation of the product so we need a plug-in to enable this capabilities. In the 6.x series this palette comes with the default and standard installation so no plug-in is required.
Ok, the first thing we have to know is that the REST Palette shares a lot of things in common with the Service palette with can use to define a Web Service without using the SOAP Palette, so if you have any experience creating Web Service this way, you are going to see that’s the steps are pretty similars.
As a first step we are going to create the skeleton of our process that is going to expose the REST interface, and it’s going to be a very easy and small process only with 3 activities.
The first activity is the HTTP Receiver because we still need the HTTP connection and the data coming from the outside using HTTP. Then we are going to use the new activity the plugin provide to us named REST Dispatch and RY. Finally we have the End activity. The full process is shown in this picture:
Ok, now we have to create the interface of our REST Service and we need to create a WADL artifact. A WADL is the REST equivalent to the WSDL artifact when we are talking about SOAP Web Services. And we have two ways to do it:
- We can create an WADL artifact using the WADL Palette you are going to see in the TIBCO Designer when you install the REST plug-in and then reference it in the REST Dispatch and Reply activity configuration.
- You can define it, inside the REST Dispatch and Reply activity.
In this first example we are going to do it the second way but the steps are very similar for the other one. We go to the Service Editor tab inside the REST Dispatch Activity Settings and using the Context Menu we start to create the service, as you can see here:
In our case we are going to create a Rest Service called “RestService” with one Resource inside called “TestResource” and inside one method called “sayHello”, as you can see here:
There are a few aspects that are important regarding the configuration of this service definition:
- When you create the Resource, you have to specify the Resource Path, that’s a URL relative path that later you are going to have to use to do the invocation. Think that the complete URL is going to be something similar to this: http://server:port/<resource>/ and then the HTTP Method is the one that is going to decide with operation are you invoking.
- When you create the resource, you also have to define the parameters of the resource and you have a table to do that. In our case we are going to create one parameter named ‘name’.
- When you create the method you have to specify a BW Sub-Process that is going to be the one who is really implementing the service. In our case the service is so simple that we don’t need any aditional activity. We only use the Start and the End, because we want to concatenate the input parameter to a constant string.
- When you already specify the subprocess you have to assign which input parameter from the BW Process should be map into the BW Subprocess and which output parameters should be recovered from the process. To do that you have the “Bind” button inside the method definition.
And that’s it! You have your API REST completed and ready to test. To do that, in my case I’m using the SOAP UI. To create the request in the SOAP UI we need the WADL file, and we can export it using the button “Export WADL” inside the REST Dispatch and Reply settings.
As usual, you can check the code in our GitHub repo and try it yourself. Here is the direct link: Download!