TIBCO Step By Step Tutorial: How to Handle Exceptions

Exceptions are one of the most familiar ugly things that programmers of any language have to deal with. When it comes to exceptions, TIBCO is also not an exception. While developing business processes in TIBCO designer, a large number of possible exception types may come across in your way which require you attention.

In this step by step TIBCO Exception Handling tutorial, I will explain you how exceptions are handled in TIBCO BW.

Example Scenario for TIBCO Exception Handling Tutorial

Following my principle of “Simple is better”, I have chosen a simple scenario for this tutorial. Let’s suppose we want to have an application which takes an employee name through HTTP request and for that name, it looks for an xml file in local file system and stores the xml data into a database table.

We want to handle possible exceptions in the said scenario so that user gets proper response over HTTP after sending request to TIBCO process.

Below are the steps for TIBCO Exception Handling Tutorial:

Step 1: Create a Process with HTTP Receiver as Process Starter

The process that I have created for this tutorial takes on HTTP Parameter “name” as input via POST method as shown in the screenshot below.

http receiver parameter

 

This process will have following activities:

  • HTTP Receiver to act as process starter to get user request on the specified connection (I have created HTTP Connection with host as localhost and port as 6700 for this example).
  • Read File activity to read xml data from a file.
  • JDBC Update activity to store the file content in a database table.
  • Catch activity to catch exceptions in the code.
  • Send HTTP Response activity to return back response to the requesting source (browser in our case).

Step 2: Configure Read File Activity

In this example, we have to read files from the folder E:\ajmal\TestData. Whatever user sends in name parameter in HTTP request, will be used to get file from the file directory. E.g. in my local file directory, I have created XML file with the name abbasi.xml.

list of files

So if user sends abbasi in the name parameter, below concatenation for file name will result in the file name as “abbasi.xml”.

read data file name

 

Step 3: Configure JDBC Update Activity

After reading content from XML file, it will be stored into a database table in our example. For this we need to configure JDBC Update activity as shown below:

store to db configuration

 

File content read using Read File activity are mapped to data which will be stored in the database table:

store to db input

 

Step 4: Configure Catch Activity to Catch FileNotFound Exception

Just to give you an idea how to handle a particular type of exception, I have used Catch activity inside group which will handle “FileNotFound” exception. This exception will arise when user sends a name in http request for which file doesn’t exist in the given path (E:\ajmal\TestData\).

catch file not found exception

 

Step 5: Configure Send HTTP Response activity

In the example, there are three scenarios for which we need to send response back for http request:

  1. When operation gets successful
  2. When an exception is thrown and is caught properly
  3. When exception is thrown but not handled explicitly

Success condition that we use to check if operation is successful will be the value of $Error/ErrorReport/MsgCode variable. If this variable is null it means there was no error in the process.

success transition condition

In this case, we will send back response with the text “Operation Successful” which is configured as shown below:

success http response

 

In the scenario when FileNotFound exception is thrown and caught, Send HTTP Response activity is configured as shown below:

send caught exception response

 

For all other types of exceptions, we have a Catch activity where we have checked “Catch All”. So this catch activity will catch all such exceptions which are not explicitly handled elsewhere in the code.

catch unhandled exceptions

 

We send back error message from $Error variable in case of this type of exception handling in our example as shown below:

send unhandled exception response

 

Step 6: Test TIBCO Exception Handling Code

After completing all activities of our process and successfully validating the code, our next step is to test the code for following scenarios:

  1. Testing Success Scenario
  2. Testing File Not Found Exception Scenario
  3. Testing Unhandled Exception Scenario

Testing Success Scenario:

We have a file with the name “abbasi.xml” in our file directory path E:\ajmal\TestData which we will read and store its content in database table.

After loading process in tester, for success scenario, user will call our process with following browser url:

http://localhost:6700/?name=abbasi

We can see in below screenshot that operation has completed without any error/exception and response has been shown on the browser:

success response test

 

We can see in the database that data has been successfully inserted in the database table:

result data stored in database table

 

 

Testing File Not Found Exception Scenario:

As we have only one file abbasi.xml in the required path, we can test FileNotFound exception scenario by passing any other name in our http request like I did below:

http://localhost:6700/?name=ajmal

 

You can see that FileNotFoundException has been caught and user has received custom error message (of course in real scenarios, you won’t just send a response message after catching an exception. You will for sure take some action for this like creation of the required file or something else).

handled exception response

 

Testing Other Exception Scenario:

Now we will do some change in the code so that we get some other type of exception which hasn’t been caught explicitly. Let’s make some wrong in our JDBC connection so that we get some JDBC exception which hasn’t been caught explicitly.

I have changed username in JDBC connection wrongly from “tibco” to “tibcoWRONG” to simulate this scenario:

wrong database credentials to test unhandled exception

 

Now when we send the request to this process, we get following response:

unhandled exception response

Ajmal Abbasi

Ajmal Hussain Abbasi is Integration Consultant By Profession with 13+ years experience in Integration domain mainly with TIBCO products. He has extensive practical knowledge of TIBCO Business Works, TIBCO Cloud, TIBCO Flogo, TIBCO Mashery, TIBCO Spotfire, EMS and TIBCO ActiveSpaces. He has worked on a number of highly critical integration projects in various sectors by using his skills in TIBCO Flogo, TIBCO API Management (Mashery), TCI, Tibco Designer, TIBCO Business Studio, Adapters, TIBCO EMS, RV, Administrator, TIBCO BE, TIBCO ActiveSpaces etc. Ajmal Abbasi has experience with MuleSoft ESB as well. Ajmal Abbasi is also experienced in the area of API Management particularly with WSO2 API management platforms. Ajmal Abbasi is also experienced in developing solutions using Core Java and J2EE Technologies. You can contact Ajmal Abbasi for Consultancy, Technical Assistance and Technical Discussions.

More Posts - Website - Facebook - LinkedIn - YouTube

4 thoughts on “TIBCO Step By Step Tutorial: How to Handle Exceptions

  1. Pingback: TIBCO Tutorial: How to Read CSV File In TIBCO BW Process | Tibco Guide

  2. Pingback: TIBCO BW Development 10 Best Practices | Tibco Guide

  3. Sundar

    Nice post. I am not able to understand the use of Parse post method data check box. Please help me in understanding it Thanks in advance.

    Reply
  4. Bibhor Anand

    Hi Ajmal,

    Could you please specify the difference between expectiondata of catch activity and $error output. Whats the significance of both.

    Reply

Leave a Reply to Sundar Cancel reply

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