1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.struts.webapp.example2;
24
25
26 import java.lang.reflect.InvocationTargetException;
27
28 import jakarta.servlet.ServletException;
29 import jakarta.servlet.http.HttpServletRequest;
30 import jakarta.servlet.http.HttpServletResponse;
31 import jakarta.servlet.http.HttpSession;
32
33 import org.apache.commons.beanutils.PropertyUtils;
34 import org.apache.struts.action.Action;
35 import org.apache.struts.action.ActionForm;
36 import org.apache.struts.action.ActionForward;
37 import org.apache.struts.action.ActionMapping;
38 import org.apache.struts.apps.mailreader.dao.User;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42
43
44
45
46
47
48
49
50
51
52 public final class EditRegistrationAction extends Action {
53 private static final long serialVersionUID = -4649550184967126100L;
54
55
56
57
58
59
60
61
62 private final static Logger LOG =
63 LoggerFactory.getLogger(EditRegistrationAction.class);
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public ActionForward execute(ActionMapping mapping,
85 ActionForm form,
86 HttpServletRequest request,
87 HttpServletResponse response)
88 throws Exception {
89
90
91 HttpSession session = request.getSession();
92 String action = request.getParameter("action");
93 if (action == null) {
94 action = "Create";
95 }
96 LOG.debug("EditRegistrationAction: Processing {} action",
97 action);
98
99
100 User user = null;
101 if (!"Create".equals(action)) {
102 user = (User) session.getAttribute(Constants.USER_KEY);
103 if (user == null) {
104 LOG.debug(" User is not logged on in session {}",
105 session.getId());
106 return (mapping.findForward("logon"));
107 }
108 }
109
110
111 if (form == null) {
112 LOG.trace(" Creating new RegistrationForm bean under key {}",
113 mapping.getAttribute());
114 form = new RegistrationForm();
115 if ("request".equals(mapping.getScope()))
116 request.setAttribute(mapping.getAttribute(), form);
117 else
118 session.setAttribute(mapping.getAttribute(), form);
119 }
120 RegistrationForm regform = (RegistrationForm) form;
121 if (user != null) {
122 LOG.trace(" Populating form from {}", user);
123 try {
124 PropertyUtils.copyProperties(regform, user);
125 regform.setAction(action);
126 regform.setPassword(null);
127 regform.setPassword2(null);
128 } catch (InvocationTargetException e) {
129 Throwable t = e.getTargetException();
130 if (t == null)
131 t = e;
132 LOG.error("RegistrationForm.populate", t);
133 throw new ServletException("RegistrationForm.populate", t);
134 } catch (Throwable t) {
135 LOG.error("RegistrationForm.populate", t);
136 throw new ServletException("RegistrationForm.populate", t);
137 }
138 }
139
140
141 LOG.trace(" Setting transactional control token");
142 saveToken(request);
143
144
145 LOG.trace(" Forwarding to 'success' page");
146 if ("Create".equals(action)) {
147 return (mapping.findForward("register"));
148 } else {
149 return (mapping.findForward("success"));
150 }
151
152 }
153 }