{
assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently.";
assert context.getResponse() instanceof HttpServletResponse : "don't support ServletResponse currently.";
HttpServletRequest request = ( HttpServletRequest ) context.getRequest();
HttpServletResponse response = ( HttpServletResponse ) context.getResponse();
FlowController flowController = context.getFlowController();
String methodName = exceptionConfig.getHandler();
Object unwrappedFormBean = InternalUtils.unwrapFormBean( form );
Method method = getExceptionHandlerMethod( context, methodName, ex, unwrappedFormBean );
if ( method != null )
{
// First see if there's a hard-coded message set.
String message = exceptionConfig.getDefaultMessage();
ActionMessage error = null;
if ( message != null )
{
error = new ExpressionMessage( message, new Object[]{ ex.getMessage() } );
try
{
// The message may be an expression. Evaluate it.
message = InternalExpressionUtils.evaluateMessage( message, form, request, getServletContext() );
}
catch ( ELException e )
{
_log.error( "error while evaluating expression in exception-handler for " + ex.getClass().getName(), e );
}
}
if ( message == null )
{
// No hard-coded message. Get the message based on the message key.
String messageKey = exceptionConfig.getKey();
if ( messageKey != null && messageKey.length() > 0 )
{
message = getMessage( context, messageKey, null, null );
}
}
//
// Expose the exception to the errors tag.
//
String msgKey = exceptionConfig.getKey();
if ( error == null ) error = new ActionMessage( msgKey, ex.getMessage() );
storeException( request, msgKey, error, exceptionConfig.getScope() );
return flowController.invokeExceptionHandler( method, ex, message, unwrappedFormBean,
form, actionMapping, request, response,
exceptionConfig.isReadonly() );
}
else
{
//
// This shouldn't happen except in out-of-date-class situations. JpfChecker
// should prevent this at compilation time.
//
String err;
if ( form != null )
{
err= Bundle.getString( "PageFlow_MissingExceptionHandlerWithForm",
new Object[]{ methodName, form.getClass().getName() } );
}
else
{
err = Bundle.getString( "PageFlow_MissingExceptionHandler", methodName );
}
InternalUtils.sendError( "PageFlow_Custom_Error", null, request, response,
new Object[]{ flowController.getDisplayName(), err } );
return null;
}
}