Technical Notes |
|
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:
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.
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.
Follow these steps to verify that the exception error has been properly set.
The error message "User-defined error (CustInquiryPanel) detected during operation ToAcctProfile from entity CustInquiryPanel: Invalid account number" should be displayed.
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; } |
To obtain the java and ReadMe files for this example, download catchProcedureException.zip from the Download Library.
To install the Event Handler, follow these steps.
To test the event handler, follow these steps.
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.