Skip to Content

This blog will explain the method to propagate your own custom error text on the communication channel monitor logs and to the standard alert framework from Custom Adapter Module in PI 7.1.

It will also discuss on few points on general exception handling in custom adapter module.

Motivation :

Lets consider , we have a requirement where the custom adapter module had to raise an exception based on certain business logic.

The exception raised from the custom module should be displayed on the communication channel monitor log and the same should be propagated to the standard alert framework. So that the alert mails received should have the exact error text raised in the custom module.

Challenge :

The obvious way to address this would  be to throw a ModuleException with a custom error text in the Custom Adapter Module. However, raising a ModuleException only with your own custom text does not propagate it neither to the Communication Channel Monitor Logs nor to the standard alert framework .

The normally followed way would be to throw ModuleException object with your custom text in the exception as below :

Please see the below code snippet from the module code :

image1.JPG

Unfortunately, by using the above method neither the communication channel logs displays the raised custom text nor it is propagated to the standard alert framework. See below screenshots.

Communication Channel Monitor Logs Screenshot:

image2.JPG

If you observe the communication channel monitor log display “Error: null” rather than “Your  custom error message” which was expected.

The same text “Error: null” is passed to the alert framework, hence the same is populated in the alert mails.

Below is the screenshot from a alert mail triggered by the standard alert framework:

image3.JPG

Solution:

In-order to address the above  challenge, you can follow the below procedure.

Step 1: In addition to your module class, create your own Custom Exception class as below : 

Code snippet for creating your custom exception class.In this example I am using the custom exception class name as RecordMismatchException.

image4.JPG

Step 2:  Code snippet for raising and handling the custom exception in the adapter module class

image5.JPG

You can create your own exception class and replace the text as per your requirement.

The important point in the above code is to pass the cause while throwing a ModuleException from custom module, so that its caught by the caller of the module and is handled.


That is it ! You can now verify if it works.

Step 3 : You can now verify whether the error message raised in module is displayed on the communication channel monitor log and passed to the alert framework.

a.Communication channel monitor is displaying the required error text :

image6.JPG

b.Alert mail generated by the alert framework has the required error message :

image7.JPG

Bingo! it works . You can now see the custom text both in channel log and alert mails.

Assumption, the alert category and the alert rule is already defined in the PI system.

Note :

  1. The above procedure is tested on PI 7.1 SP5 Version with Custom Module used with the File Adapter
  2. The above procedure can also be used for throwing standard Java exception too and will not need  any Custom Exception class for it.

This is my first blog, I will be glad to know your views/suggestion or feedback on it to improve.

Hopefully, this blog will be helpful to the PI community

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Stuart Begg

    Vishal,

    Very useful information. I have followed this technique and I am seeing the exception coming through the alert framework and delivering emails. I cannot however, find a way to include/see the text of my custom exception in the body of the email as you showed in your example email text.

    Thanks.

    (editted for spelling)

    (0) 

Leave a Reply