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 tutorial, I will explain you how exceptions are handled in TIBCO BW.
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.
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.
So if user sends abbasi in the name parameter, below concatenation for file name will result in the file name as “abbasi.xml”.
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:
File content read using Read File activity are mapped to data which will be stored in the database table:
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\).
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:
- When operation gets successful
- When an exception is thrown and is caught properly
- 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.
In this case, we will send back response with the text “Operation Successful” which is configured as shown below:
In the scenario when FileNotFound exception is thrown and caught, Send HTTP Response activity is configured as shown below:
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.
We send back error message from $Error variable in case of this type of exception handling in our example as shown below:
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:
- Testing Success Scenario
- Testing File Not Found Exception Scenario
- 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:
We can see in below screenshot that operation has completed without any error/exception and response has been shown on the browser:
We can see in the database that data has been successfully inserted in the 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:
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).
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:
Now when we send the request to this process, we get following response: