Example: Catching a timeout Exception

In this topic ...

Catching a Timeout Exception

Testing the Error Handler

Related Topics ...

Overview: Handling Errors

How to Use the Error Handler Builder

WebSphere Portlet Factory API Documentation

We can handle the case where a service call or SQL transaction takes longer than the specified timeout value by adding an Error Handler builder call and a Method builder call to your model. The Error Handler performs a try/catch operation on the specified model action and the method determines what to do in the event the specified action fails. The following steps describe one way of catching a timeout error for a service call or SQL statement. However, the steps also illustrate the general process of handling errors in Factory applications:

To catch a timeout exception:

  1. Create a page that will be displayed if the service call or SQL transaction times out. On that page, include a named <span /> tag that you will use for a Text builder call that displays the message from the timeout exception. This example uses "FailurePage" for this page name.

  2. Add a Variable to your model. This example uses, "ErrorMessage" for the variable name.

  3. Add a Text builder call, locating it on the page and tag you created in step 1. Set its Text input to the value of the ErroMessage variable. For example, ${Variables/ErrorMessage}.

  4. Add a Method, named handleTimeout, with the following Body value:

{

  HttpServletRequest request = webAppAccess.getHttpServletRequest();

  Throwable ex = (Throwable)request.getAttribute("bowstreet.errorhandler.Exception");

  String actionName = (String)request.getAttribute("bowstreet.errorhandler.ActionName");

  String errorMessage = ex.toString() + " occurred in: " + actionName;

  webAppAccess.getVariables().setString("ErrorMessage", errorMessage);

  webAppAccess.processPage("FailurePage");

}

  1. Add an Error Handler builder call to your model, with the following input values:

  2. Try Action -- Set to the invoke method for the service call or SQL statement. For example, ServiceCallTest.invoke.

  3. Catch Action -- Set to the model action that handles the error. In this case, handleTimeout.

 

Testing the Error Handler

To test the error handler you just created, set the timeout input for the service call to 0 and run the model. Your FailurePage displays with the error message associated with the timeout displayed by the Text builder call. The following text is the timeout message associated with a timeout error for a service call:

[SOAPException: faultCode=SOAP-ENV:Client; msg=Read timed out; targetException=java.net.SocketTimeoutException: Read timed out] occurred in: TimeoutTest2.invoke