1 7 package com.inversoft.verge.mvc.controller.actionflow; 8 9 10 import java.io.IOException ; 11 12 import javax.servlet.RequestDispatcher ; 13 import javax.servlet.ServletException ; 14 import javax.servlet.http.HttpServletRequest ; 15 import javax.servlet.http.HttpServletResponse ; 16 17 import org.apache.log4j.Logger; 18 19 import com.inversoft.verge.mvc.MVCException; 20 import com.inversoft.verge.mvc.controller.GenericResult; 21 import com.inversoft.verge.mvc.controller.LongTxnSetup; 22 import com.inversoft.verge.mvc.controller.Result; 23 import com.inversoft.verge.mvc.controller.actionflow.config.BaseNamespace; 24 import com.inversoft.verge.mvc.controller.actionflow.config.Namespace; 25 import com.inversoft.verge.mvc.controller.actionflow.config.Node; 26 27 28 58 public class BaseExceptionHandler implements ExceptionHandler { 59 60 63 private static final Logger logger = Logger.getLogger(BaseExceptionHandler.class); 64 65 69 public static final String ERROR_PAGE_SYSTEM_PROPERTY = "verge.controller.actionflow.errorPage"; 70 71 74 public static final String REQUEST_EXCEPTION_KEY = "exception"; 75 76 77 80 public BaseExceptionHandler() { 81 } 82 83 84 91 public boolean handleException(Exception exception, ActionFlowAction action) { 92 93 assert (action != null) : "action == null"; 94 95 HttpServletRequest request = action.getHttpServletRequest(); 96 HttpServletResponse response = action.getHttpServletResponse(); 97 String url = System.getProperty(ERROR_PAGE_SYSTEM_PROPERTY); 98 99 if (url == null && action.getNode() != null) { 100 Namespace namespace = action.getNode().getNamespace(); 101 if (namespace != null && namespace instanceof BaseNamespace) { 102 url = ((BaseNamespace) namespace).getErrorPage(); 103 } 104 } 105 106 RequestDispatcher rd = null; 107 boolean result = false; 108 if (url != null) { 109 110 Node node = action.getNode(); 112 if (node.isLongTxnEnabled()) { 113 result = handleLongTxn(action, url); 114 } else { 115 rd = request.getRequestDispatcher(url); 116 try { 117 rd.forward(request, response); 118 result = true; 119 } catch (IOException ioe) { 120 logger.error("Error while forwarding to error page", ioe); 121 } catch (ServletException se) { 122 logger.error("Error while forwarding to error page", se); 123 } 124 } 125 } 126 127 return result; 128 } 129 130 146 protected boolean handleLongTxn(ActionFlowAction action, String url) { 147 boolean result = false; 148 HttpServletRequest request = action.getHttpServletRequest(); 149 HttpServletResponse response = action.getHttpServletResponse(); 150 LongTxnSetup setup = action.getNode().getNamespace().getLongTxnSetup(); 151 if (setup != null) { 152 String longTxnURL = setup.getLongTxnEndURL(action); 153 String category = setup.getLongTxnURLCategory(action); 154 Result ret = new GenericResult(url, category); 155 156 try { 157 ActionFlowExecutor.handler.handleEndLongTxn(request, 158 response, longTxnURL, ret); 159 result = true; 160 } catch (MVCException mvce) { 161 logger.error("Error while handling long transaction " + 162 "ending inconjunction with an error page", mvce); 163 } 164 } 165 166 return result; 167 } 168 } | Popular Tags |