1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.util.genelv.struts;
19
20 import com.finalist.util.genelv.exceptions.BusinessLogicException;
21 import com.finalist.util.genelv.exceptions.WrappedEJBException;
22 import org.apache.log4j.Category;
23 import org.apache.struts.action.Action;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27
28 import javax.servlet.ServletException;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import java.io.IOException;
32 import java.rmi.RemoteException;
33
34 /***
35 * Implementation of <strong>GenericAction</strong>
36 *
37 * @author Gerard van de Weerd
38 * @version $1.0
39 */
40 public abstract class GenericAction extends Action {
41 static Category log = Category.getInstance(GenericAction.class);
42
43
44 /***
45 * Method perform
46 *
47 *
48 * @param mapping
49 * @param form
50 * @param request
51 * @param response
52 *
53 * @return
54 *
55 * @throws IOException
56 * @throws ServletException
57 *
58 */
59 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
60 throws IOException, ServletException {
61 try {
62
63 GenericForm childForm = (GenericForm) form;
64 if (childForm != null) {
65 Throwable formRaisedException = childForm.getRaisedException();
66 if (formRaisedException != null) {
67
68 log.error("exception occurred in ActionForm: " + childForm.getClass().getName());
69 throw formRaisedException;
70 }
71 }
72
73 ActionForward af = this.doPerform(mapping, form, request, response);
74 if (af == null)
75 return (mapping.findForward("success"));
76 else
77 return af;
78 }
79 catch (RemoteException ex) {
80 log.error("Remote Exception occured: ", ex);
81 Throwable saveEx = ex;
82 Throwable innerEx = ex.detail;
83
84 if (innerEx instanceof WrappedEJBException) {
85 saveEx = innerEx;
86 }
87 request.getSession().setAttribute(ExceptionConstants.EXCEPTION, saveEx);
88 return mapping.findForward(ExceptionConstants.EXCEPTION_PAGE);
89 }
90 catch (BusinessLogicException ex) {
91 log.error("BusinessLogicException occured: ", ex);
92 request.getSession().setAttribute(ExceptionConstants.EXCEPTION, ex);
93 return mapping.findForward(ExceptionConstants.EXCEPTION_PAGE);
94 }
95
96 catch (Exception ex) {
97 log.error("A checked exception occured: ", ex);
98 request.getSession().setAttribute(ExceptionConstants.EXCEPTION, ex);
99 return mapping.findForward(ExceptionConstants.EXCEPTION_PAGE);
100 }
101 catch (Throwable t) {
102 log.error("An unchecked exception occured: ", t);
103 request.getSession().setAttribute(ExceptionConstants.EXCEPTION, t);
104 return mapping.findForward(ExceptionConstants.EXCEPTION_PAGE);
105 }
106 }
107
108
109 /*** The actual perform function: MUST be implemented by subclasses. */
110 abstract public ActionForward doPerform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws RemoteException, WrappedEJBException, Exception;
111
112 }