1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package jdbcadmin.web.actions;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionError;
30 import org.apache.struts.action.ActionErrors;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34
35 import jdbcadmin.core.data.ConnectionInfo;
36 import jdbcadmin.web.ContexteManager;
37 import jdbcadmin.web.forms.ConnectionForm;
38
39 /***
40 * Connection Action.
41 * @struts.action
42 * name="connectionForm"
43 * path="/connection"
44 * @struts.action-forward
45 * name="main"
46 * path="/listSchema.do"
47 * @author Thomas Recloux (trecloux@norsys.fr)
48 */
49 public class ConnectionAction extends Action {
50
51 /*** logger */
52 private static Log logger = LogFactory.getLog(ConnectionAction.class);
53
54 /***
55 * {@inheritDoc}
56 */
57 public ActionForward execute(
58 ActionMapping aMapping,
59 ActionForm aForm,
60 HttpServletRequest aRequest,
61 HttpServletResponse aResponse)
62 throws Exception {
63
64 String forward = "main";
65 ActionErrors errors = new ActionErrors();
66
67 try {
68 if (aRequest.getSession().getAttribute(ContexteManager.RESTRICTION_KEY) != null) {
69
70 ConnectionForm form = (ConnectionForm) aForm;
71 ConnectionInfo cnxInfos = new ConnectionInfo();
72 String jndiName = form.getJndiName();
73 if (jndiName != null && !jndiName.equals("")) {
74 cnxInfos.setDataSourceJndiName(form.getJndiName());
75 }
76 cnxInfos.setUserName(form.getUserName());
77 cnxInfos.setUserPassword(form.getUserPassword());
78 cnxInfos.setUrl(form.getUrl());
79 cnxInfos.setDriverName(form.getDriverName());
80 if (form.getDriverJar() != null) {
81 cnxInfos.setDriverJarData(form.getDriverJar().getFileData());
82 }
83
84 ContexteManager.setCnxInfos(aRequest, cnxInfos);
85 } else {
86 forward = "index";
87 }
88
89 } catch (Exception e) {
90 if (logger.isErrorEnabled()) {
91 logger.error("Unexpected error during the connection", e);
92 }
93 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e.getMessage()));
94 forward = "error";
95 }
96
97 if (!errors.isEmpty()) {
98 saveErrors(aRequest, errors);
99 }
100 return aMapping.findForward(forward);
101
102 }
103
104 }