Verastream Host Integrator Event Handler Examples: Catch a Procedure Exception

  • 7021535
  • 17-Aug-2006
  • 02-Mar-2018

Environment

Verastream Host Integrator

Situation

This technical note provides an example of how to use the Verastream Host Integrator Procedure Event Handler to catch and automatically correct a Java exception error that occurs when a table procedure is executed.

The example shows how to catch an invalid user ID number entry and automatically replace it with a valid ID number. (Note: This is a simplified example and does not reflect a real-life scenario.)

The example is built upon the CCSDemo model, which is included with Verastream Host Integrator.

This example uses:

Model: CCSDemo
Entity: CustInquiryPanel
Operation: toAcctProfile

Resolution

Configure the Error Message

By default, if operation toAcctProfile on entity CustInquiry Panel receives an invalid account number, Verastream remains at the CustInquirePanel entity. To configure Verastream to display a custom error, such as "Invalid account number," when an exception is thrown, follow these steps to define CustInquirePanel as an error entity for this operation.

  1. Select the CustInquiryPanel entity, click the Operations tab, and then select ToAcctProfile.

Notice that the default AcctNumber value is 167439459; this is the only valid account number for the emulated CCSDemo application. By default, when an invalid account number is entered, CCSDemo returns to (or remains on) the CustInquiryPanel entity, with no error message.

  1. Click Destinations and add CustInquirePanel as a user-defined error entity.
  2. Select CustInquiryPanel, and in the Return field, enter the text "Invalid account number."
  3. Click Close, and then click Apply.

Follow these steps to verify that the exception error has been properly set.

  1. Click Debug > Procedure test.
  2. Select the table and procedure you want to use.
  3. In the Procedure filters field, enter an invalid account number, such as 167349, and then click Execute.

The error message "User-defined error (CustInquiryPanel) detected during operation ToAcctProfile from entity CustInquiryPanel: Invalid account number" should be displayed.

Configure the Event Handler

Using event handler code, Verastream can be configured to catch GetAccount table procedure exceptions, correct the AcctNumber filter parameter to a valid number, and then re-execute the procedure.

In the following code, when a valid account number is entered, the event handler executes the process. When an invalid account number is entered, an exception error is thrown, this code catches the exception error string, checks the exception message for the user-defined error text, iterates through the filter parameters map, and then replaces the invalid AcctNumber key value with a valid account number.

/********* handle valid account numbers ********/
    try {
      recSet= event.defaultProcedure(params, 0);
          return recSet;
    }
/********* catch exception error string ************/
     catch (ApptrieveException e) {
        msg = new String(e.getMessage());
        if (msg.indexOf("Invalid account number") != -1) 
{/ -1 means not found
/********** modify procedure parameters for **********/
/********** invalid account numbers ******************/
            for (int i=0; i<params.length; i++)  {
                filterMap = params[i].getFilterParameters();
                mapItr = filterMap.entrySet().iterator();
                while (mapItr.hasNext())  {
                    /*** find filter parameter "AcctNumber" ***/
                    filterEntry = 
(java.util.Map.Entry)mapItr.next();
                    if (((String) 
filterEntry.getKey()).compareTo("AcctNumber")==0) {
                        filterEntry.setValue("167439459");
                        break;
                    }
                }
            }
        }
        else
            break;
    }

Download the Example

To obtain the java and ReadMe files for this example, download catchProcedureException.zip from the Download Library.

Install the Event Handler

To install the Event Handler, follow these steps.

  1. Copy catchProcedureException.java to the \models\<your model>\scripts\src directory.
  2. In Design Tool, click Events > Rebuild.
  3. Click Model > Tables, select any procedure, and then click Advanced Properties.
  4. Under Event handler, select logTransactionToXML, and then click Properties and note the description.
  5. Save the changes.

Test the Event Handler

To test the event handler, follow these steps.

  1. Click Debug > Procedure test.
  2. Select the table and procedure you want to use.
  3. In the Procedure filters field, enter an invalid account number, such as 167349, and then click Execute.

Without the execute procedure event handler to catch the exception, the result of the procedure test is the error message "User-defined error (CustInquiryPanel) detected during operation ToAcctProfile from entity CustInquiryPanel: Invalid account number".

With the event handler in-place, the exception is caught, the account number is corrected, the procedure is rerun and the procedure outputs correctly display CARLA P SMITH as the only account record found.

Additional Information

Legacy KB ID

This article was originally published as Attachmate Technical Note 10045.