How to implement rest services using BW 5

How to implement rest services using BW 5

What is REST?

REST (Representational State Transfer) is an architectural style for designing Public APIs and networked applications in the form of Web Services.  REST is a lightweight and non-standardized approach towards development of Web Services as it doesn’t comply to any hard and fast standards unlike SOAP.
REST based Web Services are called RESTful web services and such services use HTTP Protocol for data transport. XML, JSON etc. are used as data formats for input and output of RESTFul web service operations.

REST vs SOAP

REST, unlike SOAP is not a protocol.
REST is an architectural style and a design for network-based software architectures.
REST concepts are referred to as resources. A representation of a resource must be stateless. It is represented via some media type. Some examples of media types include XML, JSON, and RDF. Resources are manipulated by components. Components request and manipulate resources via a standard uniform interface. In the case of HTTP, this interface consists of standard HTTP ops e.g. GET, PUT, POST, and DELETE.

Scenario to Create a RESTFUL Web Services in Tibco BW:-

Lets take simple scenario to create Restful web services in Tibco bw. This service will be used to query Employee Details from a database table based on EMP ID.

For Testing Purpose, the client process will be sending a hard coded EMPID for which, our service will fetch the Employee details from the database and will send back as a service response in XML String format.
Let’s now go step by step to develop our Restful Web Service:

Creating Shared Connection Resources for HTTP and JDBC:

HTTP  JDBC Restful Service

Restulful JDBC Connection

XML Schema to be used as Restful Service Input and Output

XML Restful Service

Let’s Create Implementation process for our RESTFUL Web Services in Tibco BW.

Our business logic in this example case is very simple. We are just going to use the schema that we created in above step as Input and Output in our process and will use JDBC Query Activity to query account details from the database so that account details are sent as output from the process.
In the JDBC Query Activity configuration tab, we are going to write following query to fetch the Employee details from the database:

Jdbc query
JDBC Query returns Multiple records as the output which is mapped to End activity Schema elements so that It is sent as an output from this process.

Jdbc Employee details

Create RESTful Service Using REST Dispatch and Reply activity

Let’s create service by using REST Dispatch and Reply activity from the REST & JSON Palette. Using REST Dispatch and Reply activity, we can expose a BW process as a RESTFul service. The BW Implementation process that we created will be used in this case as RESTful service implementation process.
The Starter activity for the process with REST Dispatch and Reply is HTTP Receiver and we will use the connection created in earlier steps.

Rest Dispatch & Reply

In the Service Editor tab, click on the application.
Right Click on the Application and choose Add–>RestService
A new REST Service will be added under the application. I have renamed it to EmployeDetailsService.
For this EmployeDetailsService, specify the base URL. This URL should be same which you configured in your HTTP Connection:

Rest Dispatch Service

rest dispatch employee

Now Right Click on your service in the Service Editor tab and choose Add–>Resource
New Resource will be added under the service. I have renamed this resource to EmployeeResource. We don’t need to add any parameters as we will add parameters at method level instead.
The Resource will look like below:

restful resource
ADD a method and name it as GetEmployeeDetails and select the request and response schema

get employee details

After adding the request and response elements under the Method.
Select the business process at the Method Level to associate the Business Process with the Method. This is similar to our Operation and Implementation process in Service Activity.

get employee service

Now click on the method name so that Bind button in the bottom appears. Using Bind button, we will map the Input and Output for our service for this method.
As you can see in below diagram that we have used Bind button and then mapped EmpID as Input. Using Render-XML function, the response is mapped as output string:

render xml

With this step we complete our configuration work for REST Dispatch and Reply activity.

CLIENT Process

To Invoke RESTFul Service, let’s create a new process and use Invoke REST API activity from REST & JSON Palette in it. In the configuration tab of Invoke REST API activity, specify the Resource URI.
client process

Under the input Editor of Invoke REST API we have an existing complex element named as Query which a child element as PARAM. Lets rename PARAM as EMPID which is the request parameter in our scenario as show below

params id

For testing purpose lets hard code the EMPID as 1 as shown below

empid

Load the Client and the RESTFUL Service in our TIBCO BW Tester and create a job on Client process to invoke the RESTFUL service via HTTP Receiver.

restful http reciver

6 Comments
  • Venkateswara Rao
    Posted at 11:58h, 28 July Reply

    Please provide TIBCO BW REST&JSON plugin

    • cblwebsite
      Posted at 17:25h, 28 July Reply

      Hi venkateswara Rao, Thanks for your comment. Do you need information or article on Tibco Bw Rest JSON Plugin?

      • Venkateswara Rao
        Posted at 11:29h, 29 July Reply

        I need TIBCO BW REST&JSON plugin for TIBCO BW 5.x and
        I need examples on Restful Webservices

  • vadiraj
    Posted at 16:05h, 29 August Reply

    How the rest wil come to know that it has to invoke the process QueryEmpDetails that is defined above.There is no mapping I am able to find for the same.Bind simply maps input and outputs of the service but how Rest Dispatch And Display activity will come to know that it has to invoke the QueryEmpDetails process.

    • Raghu
      Posted at 04:02h, 24 February Reply

      Based on the resource name defined while creating the REST server. http://localhost:9578/employee
      “employee” is the resource which gets identified by the server and forwards the requests to the corresponding process.
      Hope I’m clear

  • Sateesh Reddy
    Posted at 08:31h, 23 February Reply

    If we create multiple methods in the same resource which method will be called? we are not giving method name anywhere.

Post A Comment