REST Service Tutorial

Last updated on Sep 27 2021
Dayanand Salve

Table of Contents

REST Service Tutorial

 

The REST Bookstore sample lets you explore the REST tooling in TIBCO Business Studio. You can import this sample into TIBCO Business Studio through File Explorer and examine the project and the solution implemented by it.
The processes in the sample implement different aspects of a bookstore, such as adding books, deleting a book, and getting a list of books or a single book by ISBN. For more information about the sample, see the topic called “Using REST to Manage Books for a Bookstore” in the Samples guide. This tutorial walks you through the steps to build an additional REST service for the sample and test it in the debugger.
You can use the Swagger UI to invoke the operations for the REST resource.

Prerequisites

Before starting the tutorial, you must have PostgreSQL installed on your machine, with the required database and tables created.
Install the latest version of Google Chrome.

Creating a New Process
These steps show how to create a new process.

Procedure

1. Open TIBCO Business Studio.

2. Open the Design perspective by clicking the icon in the upper right.

3. Click the File Explorer tab. If the tab is not visible, click Window > Show View > Other > Filesystem > File Explorer and click OK.

4. Click File > Switch Workspace and select or open a clean new workspace.

5. In the samples directory, select binding > rest > Bookstore and double-click tibco.bw.sample.binding.rest.BookStore.zip. This opens the project in the Project Explorer.

6. In the Project Explorer, expand the tibco.bw.sample.binding.rest.BookStore project.

7. You can also import the sample using the File > Import > General > Existing Studio Projects into Workspace > Select Archive File > Browse option.

8. The project is displayed in the Project Explorer panel on the left.

REST Service Tutorial
REST Service Tutorial

9. Expand the folders in the project to see all the project processes and resources. Refer to the Application Development guide for information about the folder structure.

REST Service Tutorial
REST Service Tutorial

10. Expand Processes and then expand tibco.bw.sample.binding.rest.bookstore.db. You will see BooksDB.bwp.

bwp is a BusinessWorks process.

REST Service Tutorial
REST Service Tutorial

11. Double-click BooksDB.bwp.
The BusinessWorks process comprises:

• Green chevron on the left indicates the service details.
• addBooks, getAllBooks, and so on indicate the operations implemented by this process.
• Each operation is implemented separately.

REST Service Tutorial
REST Service Tutorial

12. Double-click an operation to display the process for example, BooksPersist > addBooks.

a) In the addBooks operation, you can see a JDBC activity.
b) The activity is repeated using a ForEach group.
c) addBooksOut represents the Reponse to the web service request.

13. To add a new process package named tibco.bw.sample.rest, right-click on Processes in the Project Explorer and select New > BusinessWorks Package.

REST Service Tutorial
REST Service Tutorial

14. In the Business Works Package screen, specify tibco.bw.sample.

REST Service Tutorial
REST Service Tutorial

15. Click Finish and verify that the new package tibco.bw.sample.rest has been added in the Project Explorer.

REST Service Tutorial
REST Service Tutorial

Building a REST Service

This section details how to build a REST service.

Procedure

1. To define a REST Resource named MyBooks, select tibco.bw.sample.rest > New > BusinessWorks REST Resource.

The REST Service Wizard window opens.

REST Service Tutorial
REST Service Tutorial

2. Specify the following values in the REST Service Wizard window.
a) Resource Name: MyBooks
b) Summary: Summary about the new REST service. (default)
c) Resource Service Path: Auto-filled
d) Type of Resource: Collection (default)
e) Resource Schema: Select Browse > Schemas > Books.xsd > Books in the Select Schema Element Declaration window.
f) Operations: Select POST and GET check boxes.

3. Click Finish.
This creates a new process MyBooks.bwp process is opened in the Process Editor.

REST Service Tutorial
REST Service Tutorial

4. Open the tibco.bw.sample.binding.rest.bookstore.db process in the Project Explorer and select the BooksDB.bwp process. Drag it to the Process Editor and drop it on the implemented POST operation. A menu is displayed with two options: Create Invoke Activity and Create Reference and Wire Process.

REST Service Tutorial
REST Service Tutorial

5. Select Create References and Wire Process.
The references are added to the process. The purple chevron indicates the service and its operations that can be referenced by the process.

REST Service Tutorial
REST Service Tutorial

6. To update the POST process to invoke the appropriate external service operation:
a. Click the addBooks operation.
b. Select and drag the operation to the left of the postOut activity and drop it. An Invoke process activity is created.

REST Service Tutorial
REST Service Tutorial

7. Click the newly added activity. Select the icon and connect addBooks to postOut.

REST Service Tutorial
REST Service Tutorial

8. Click the getAllBooks operation and select, drag, and drop the operation to the left of the getOut activity in the OUT process.
9. Connect getAllBooks to getOut.

REST Service Tutorial
REST Service Tutorial

10. Save your changes.
11. Click the addBooks activity and select Properties > Input.
12. Expand the data tree in the Data Source pane to locate the Book element.

REST Service Tutorial
REST Service Tutorial

13. Drag the Book element from the left to the Book* element on the right.

14. In the pop-up window, select Make a Copy of each ” Book” and click Finish. The Input tab will look like this:

REST Service Tutorial
REST Service Tutorial

15. Save your changes.

16. Click the postOut activity and open the Properties > Input tab. Expand the post activity and drag the Book* element from left to right.

17. In the pop-up window, select the For each option and click Next. Click Finish on the Auto-Map window. The Properties > Input tab will look similar to this:

REST Service Tutorial
REST Service Tutorial

18. Click getAllBooks and select Properties > Input.
19. In the XPath Expression pane, add a dummy value to the input element, such as”Get All Books”. The input must be in quotes.

REST Service Tutorial
REST Service Tutorial

20. Click the getOut activity in the Process Editor, and select the Properties > Input tab. Expand the getAllBooks activity and choose Book* to map the Book* element from left to right. In the pop-up window, choose Make a Copy of each ” Book” and click Finish. The tab will look similar to this:

REST Service Tutorial
REST Service Tutorial

Result

Your project is complete without any errors.

 

Testing the REST Service

You can now test the REST service using the built-in tester and the Swagger UI.

Procedure

1. In the Project Explorer, expand the tibco.bw.sample.binding.rest.BookStore.application process and expand the Package Unit > Properties folder.

2. In the Properties window, open the tibco.bw.sample.binding.rest.BookStore process and set the default ApplicationProfile to match the operating system you are running on. The bracketed profile in the column head is the one that is selected:

REST Service Tutorial
REST Service Tutorial

3. Provide valid values for the application properties including a valid user name, password, and database URL to connect to your PostgreSQL database if different from the default setting.

4. Verify your JDBC connection.
a) Expand the Resources folder in the Project Explorer for the
a. tibco.bw.sample.binding.rest.BookStore process.

b) Double-click JDBCConnectionResource.jdbsResource.
c) In the JDBC Driver section of the window, click Test Connection to verify the connection. If you change the JDBC driver folder from the default, click Click Here to Set Preferences and set the JDBC driver folder to the folder where you downloaded PostgreSQL JDBC Driver.

REST Service Tutorial
REST Service Tutorial

5. Click File > Save.

6. In the Project Explorer, expand the Processes directory if it is not expanded and double-click
MyBooks.bwp.

7. Click Run > Debug Configurations.

8. In the left-hand tree of the Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.

9. Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the check box next to tibco.bw.sample.binding.rest.BookStore.application.

10. Click Debug. This runs the sample in Debug mode. The Console view is opened and shows engine messages similar to: Started BW Application [tibco.bw.sample.binding.rest.BookStore.application:1.0].

11. In the Console view, press Enter to display the prompt: <>@BWEclipseAppNode>
Enter the OSGi command lrestdoc. This lists the Swagger UI URL as the discovery URL:
[Application Name]: tibco.bw.sample.binding.rest.BookStore.application [Discovery Url]:
http://localhost:7777/tibco.bw.sample.binding.rest.BookStore.application

12. Launch the Google Chrome browser and open http://localhost:7777/ tibco.bw.sample.binding.rest.BookStore.application. Click Books or Events to see the operations. Click MyBooks to see the REST service operations you just

REST Service Tutorial
REST Service Tutorial

added.

13. Expand the Books and Events headers, and test out the operations as listed below.

Result

Click Books or Events in the Swagger UI to view the following operations for Books and Events:

Books

• Post books
• GET books
• GET book by ISBN
• PUT book by ISBN
• DELETE book by ISBN

Events

• POST Events
• GET Events
• GET Event by EventID
• PUT Event by EventID
• DELETE Event by EventID

GET books returns an output similar to the following:
GET books by ISBN returns an output similar to the following for ISBN 0061122416:

The books.log file is generated with the following information:

POST Books >{“Book”:[{“isbn”:”1451648537″,”name”:”Steve
Jobs”,”description”:”Biography of Apple Co-Founder Steve Jobs”,”authorName”:”Walter Isaacson”,”releaseDate”:”2012-10-24″,”vintage”:false,”signed”:false,”price”:21},
{“isbn”:”0385537859″,”name”:”Inferno”,”description”:”Robert Langdon returns in Dan Brown’s latest fast paced action thirller”,”authorName”:”Dan Brown”,”releaseDate”:”2013-05-14″,”vintage”:false,”signed”:true,”price”:14.09},
{“isbn”:”0399103421″,”name”:”The Godfather”,”description”:”The Godfather is an epic story of a New York’s top mafia family, loyalty, and how men of honor live in their own world, and die by their own laws.”,”authorName”:”Mario Puzo”,”releaseDate”:”1969-03-10″,”vintage”:true,”signed”:true,”price”:
50}]}
GET Books >{“Book”:[{“isbn”:”1451648537″,”name”:”Steve
Jobs”,”description”:”Biography of Apple Co-Founder Steve Jobs”,”authorName”:”Walter Isaacson”,”releaseDate”:”2012-10-24+05:30″,”vintage”:false,”signed”:false,”price”: 21},{“isbn”:”0385537859″,”name”:”Inferno”,”description”:”Robert Langdon returns in Dan Brown’s latest fast paced action thirller”,”authorName”:”Dan Brown”,”releaseDate”:”2013-05-14+05:30″,”vintage”:false,”signed”:true,”price”: 14.09},{“isbn”:”0399103421″,”name”:”The Godfather”,”description”:”The Godfather is an epic story of a New York’s top mafia family, loyalty, and how men of honor live in their own world, and die by their own laws.”,”authorName”:”Mario Puzo”,”releaseDate”:”1969-03-10+05:30″,”vintage”:true,”signed”:true,”price”:
50}]}
GET Book By ISBN >{“isbn”:”1451648537″,”name”:”Steve
Jobs”,”description”:”Biography of Apple Co-Founder Steve Jobs”,”authorName”:”Walter Isaacson”,”releaseDate”:”2012-10-24+05:30″,”vintage”:false,”signed”:false,”price”: 21}

DELETE Book By ISBN——–>”Deleted book with ISBN – 1451648537″

GET Events By ISBN—-
>{}

Testing the POST and GET Operations

An available RESTful service displays the GET operation in the Swagger UI. The POST operation is tested using the JSON service. It is important to test these operations by doing some simple tasks. This section explains how to test the POST and GET operations you just added.

Procedure

1. Click MyBooks. It expands and displays the POST and GET operations.

REST Service Tutorial
REST Service Tutorial

2. Click the POST icon to display its details.
3. Provide values to the Books parameter. You can use the JSON payload in BW_HOME\samples\binding\rest\BookStore\samplejson folder.
4. Click the Try it out! button.
5. Now click the GET icon to display its details.
6. Click the Try it out! button.
The response displays a list of books returned by the REST service from the database.

REST Service Tutorial
REST Service Tutorial

7. After you have finished, go back to TIBCO Business Studio and click the Terminate icon in the Console view to stop the process.

 

Troubleshooting

Your may encounter some errors while executing or running the process. The following are some of the possible errors you may encounter and their resolutions.

Error Encountered Resolution
Unable to insert rows into the database using the dbsetup.sql script in the scripts folder. Use the sample JSON payload from the sample json folder to post the data.
The REST Swagger UI page is not visible. Verify that the application has started and that you are accessing the correct URL. Use the lrestdoc command in the Console view to get the Swagger UI URL.
Problem markers are visible in the project. Clean the project by invoking Project > Clean or by switching to a clean new workspace.
Getting the File was not found
exception. Ensure that the books.json and book_put.json files are present at the location described in the Input_File and Input_File_1 module properties.
The PostgreSQL server does not start. Make sure you are not running as Administrator.
The database and database tables are sample located in BW_HOME\samples\binding\rest\BookStore\scripts folder . Run the dbsetup.sql script from a command line, not the psql window.
Getting an unregistered user error Role Privileges tab in the message while running the process. Select all the check boxes in the pgAdmin UI and run the process again. See the image below.

REST Service Tutorial
REST Service Tutorial

Installing PostgreSQL

This topic explains how to install the PostgreSQL database and create the database and tables required for the Bookstore tutorial.

Procedure

1. Download and install PostgreSQL from http://www.postgresql.org/download/ Note the superuser password that you create as part of the installation process. If installing on Windows, do not install or run as Administrator.
2. Open a terminal window and navigate to the root folder of the PostgreSQL installation. Open pg-env.bat and verify the path settings. Save the file if you make changes.
3. Start the server. Navigate to the bin folder of the install directory and type: pg-ctrl start Enter the password you created for the superuser.
4. Open another terminal window and navigate to the BW_HOME\samples\binding\rest\BookStore\scripts folder. Open readme.txt. For Unix systems, use the first command in the readme to start the script from the psql window. On a Windows machine, copy the second command to start the script from the command line.
5. Navigate to the PostgreSQL bin folder and paste the command line into the terminal window. Modify the command as needed. For Windows, use forward slashes in the command. Run the command to create the database, the database tables, and populates the database.
6. Open the PostgreSQL pgAdmin UI utility to see the database and tables.

So, this brings us to the end of blog. This Tecklearn ‘REST Service Tutorial’ blog helps you with commonly asked questions if you are looking out for a job in TIBCO Business Works. If you wish to learn TIBCO Business Works and build a career in Business Intelligence domain, then check out our interactive, TIBCO Business Works Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

TIBCO Business Works

TIBCO Business Works Training

About the course

Tecklearn’s TIBCO Business Works training provides in-depth knowledge on all the key fundamentals of Business Works and also develops skills to design, test, deploy, and administer the TIBCO ActiveMatrix Business Works applications. By the end of the training, you will gain confidence to clear the TIBCO Business Works certification exam.

Why should you take TIBCO Business Works?

• The average annual pay for a TIBCO BW Professional is $136,500 per annum. -Neuvoo.ca.
• TIBCO BW global market share is 2%.
• With TIBCO BusinessWorks software, integration specialists can easily implement integration strategies using traditional enterprise integration patterns to modern cloud-based API-led approaches built with microservices and containers.

What you will Learn in this Course?

Overview of Integration and TIBCO BW5 Environment

• Enterprise Integration
• Enterprise application integration (EAI)
• EAI Concepts
• Overview of TIBCO platform
• TIBCO components

Installation

• TIBCO Installation
• Why ESB

TIBCO File, Data and General Activities

• Read and Write a File
• Parsing a File data
• Polling for specific files and copy specific data to another directory

TIBCO Database Activities

• Create project using JDBC palette activities via JDBC query and JDBC update
• Advance JDBC, Process in Subsets and Batch update
• TIBCO SQL Direct and Call Procedure Implementation
• Transactions and Checkpoint

Processing data efficiently

• Data Transformation Patterns
• Structural Mapping
• Disjoint Structure Mapping
• Merging, Aggregation
• Segregation
• Common XSLT and best practices

Overview of Service Oriented Architecture

• Basic Web Services Understanding
• XML overview – XSD, DTD, XSLT, XPath
• SOA Introduction, SOA Principles and Service Orientation, SOA Pattern
• Understanding WSDL, SOAP and UDDI concepts, W3C, SDO

SOAP Service Implementation

• Create SOAP demo project in TIBCO BW
• Creation of standard HTTP soap service
• Project Creation to expose security context for a web service which is implemented using service resource
• SOAP message is signed and encrypted using X.509 token

ESB (Enterprise Service bus)

• How Messaging Works
• Messaging Features and JMS
• Overview of TIBCO EMS
• Messaging Models
• Client Service Delivery Modes
• JMS Message Format
• Acknowledgement Modes
• Development of EMS Client using TIBCO BW5
• Implementing Failover, Load Balancing using JMS Activities
• Destination Bridging to avoid writing huge code

Introduction to TIBCO Adapter Services

• Explore TIBCO ADB Adapter Explore
• Configure ADB Publication and subscription services

Advance Service Design

• Using Variables Using Sub processes, using Null Activities
• Inter Process Communication
• Extending the mapper
• Java Custom Function

Introduction to REST

• Installing active matrix business work plug-in for REST and JSON 2.0
• Fundamentals of REST and REST Architectural Elements
• RESTful Service and REST Operation Details
• REST Clients: Postman, Advance Rest Client and SOAP UI
• Creation of REST service
• Conversion of business logic into REST service
• Binding, input binding, output binding, mapping activity
• SOAP Demo

Extending Business Works

• Java activities, Custom Palettes Engine Command, Error Handling, Plugins and add-ons
• SOAP Project with two endpoints, one for HTTP and one for JMS
• Securing Web Services

TIBCO Administration

• TIBCO BW Run time Architecture
• Communication and Domain creation
• Management and Configuration of Robust Domain
• Managing and Monitoring Deployments
• Fault tolerance and load balancing
• Domain, process archive and shared archive
• HAWK agent
• Performance Tuning
• BW Engine
• Deployment and Management
• Loading using AppManage

Introduction to Tools like Ant, Eclipse, Maven, Jenkins

0 responses on "REST Service Tutorial"

Leave a Message

Your email address will not be published. Required fields are marked *