001 package com.mockrunner.struts;
002
003 import javax.servlet.http.HttpServletRequest;
004 import javax.servlet.http.HttpServletResponse;
005
006 import org.apache.struts.action.ActionForm;
007 import org.apache.struts.action.ActionMapping;
008
009 /**
010 * Generic interface for exception handlers. The default implementation
011 * is {@link DefaultExceptionHandlerConfig} and uses the Struts
012 * exception handling mechanism. In special cases, you may provide your own
013 * implementations of this interface, that may be independent from
014 * the Struts exception handling mechanism.
015 * Exception handler are called if an action throws an exception.
016 * Use {@link ActionTestModule#addExceptionHandler} to register an exception handler.
017 */
018 public interface ExceptionHandlerConfig
019 {
020 /**
021 * Returns if this handler is able to handle the exception.
022 * @return <code>true</code> if this handler is able to handle the exception,
023 * <code>false</code> otherwise
024 */
025 public boolean canHandle(Exception exception);
026
027 /**
028 * Handles the exception.
029 * @param exception the exception
030 * @param mapping the current <code>ActionMapping</code>
031 * @param form the current <code>ActionForm</code>
032 * @param request the current request
033 * @param response the current response
034 * @return the handler return value, usually an <code>ActionForward</code>,
035 * but may be any object
036 */
037 public Object handle(Exception exception, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception;
038 }