Source code: org/apache/webapp/admin/context/EditContextAction.java
1 /*
2 * Copyright 2001-2002,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.apache.webapp.admin.context;
18
19 import java.io.IOException;
20 import java.util.Locale;
21 import javax.servlet.ServletException;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.servlet.http.HttpSession;
25 import org.apache.struts.action.Action;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.util.MessageResources;
30
31 import javax.management.MBeanServer;
32 import javax.management.ObjectName;
33
34 import org.apache.webapp.admin.ApplicationServlet;
35 import org.apache.webapp.admin.Lists;
36
37 /**
38 * The <code>Action</code> that sets up <em>Edit Context</em> transactions.
39 *
40 * @author Manveen Kaur
41 * @version $Revision: 303641 $ $Date: 2005-01-14 18:55:41 -0500 (Fri, 14 Jan 2005) $
42 */
43
44 public class EditContextAction extends Action {
45
46
47 /**
48 * The MBeanServer we will be interacting with.
49 */
50 private MBeanServer mBServer = null;
51
52
53 // --------------------------------------------------------- Public Methods
54
55 /**
56 * Process the specified HTTP request, and create the corresponding HTTP
57 * response (or forward to another web component that will create it).
58 * Return an <code>ActionForward</code> instance describing where and how
59 * control should be forwarded, or <code>null</code> if the response has
60 * already been completed.
61 *
62 * @param mapping The ActionMapping used to select this instance
63 * @param actionForm The optional ActionForm bean for this request (if any)
64 * @param request The HTTP request we are processing
65 * @param response The HTTP response we are creating
66 *
67 * @exception IOException if an input/output error occurs
68 * @exception ServletException if a servlet exception occurs
69 */
70 public ActionForward execute(ActionMapping mapping,
71 ActionForm form,
72 HttpServletRequest request,
73 HttpServletResponse response)
74 throws IOException, ServletException {
75
76 // Acquire the resources that we need
77 HttpSession session = request.getSession();
78 Locale locale = getLocale(request);
79 MessageResources resources = getResources(request);
80
81 // Acquire a reference to the MBeanServer containing our MBeans
82 try {
83 mBServer = ((ApplicationServlet) getServlet()).getServer();
84 } catch (Throwable t) {
85 throw new ServletException
86 ("Cannot acquire MBeanServer reference", t);
87 }
88
89 // Set up the object names of the MBeans we are manipulating
90 // Context mBean
91 ObjectName cname = null;
92 // Loader mBean
93 ObjectName lname = null;
94 // Manager mBean
95 ObjectName mname = null;
96
97 StringBuffer sb = null;
98 try {
99 cname = new ObjectName(request.getParameter("select"));
100 } catch (Exception e) {
101 String message =
102 resources.getMessage(locale, "error.contextName.bad",
103 request.getParameter("select"));
104 getServlet().log(message);
105 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
106 return (null);
107 }
108 String name = cname.getKeyProperty("name");
109 name = name.substring(2);
110 int i = name.indexOf("/");
111 String host = name.substring(0,i);
112 String path = name.substring(i);
113 // Get the corresponding loader
114 try {
115 sb = new StringBuffer(cname.getDomain());
116 sb.append(":type=Loader");
117 sb.append(",path="+path);
118 sb.append(",host="+host);
119 lname = new ObjectName(sb.toString());
120 } catch (Exception e) {
121 String message =
122 resources.getMessage(locale, "error.managerName.bad",
123 sb.toString());
124 getServlet().log(message);
125 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
126 return (null);
127 }
128
129 // Session manager properties
130 // Get the corresponding Session Manager mBean
131 try {
132 sb = new StringBuffer(cname.getDomain());
133 sb.append(":type=Manager");
134 sb.append(",path="+path);
135 sb.append(",host="+host);
136 mname = new ObjectName(sb.toString());
137 } catch (Exception e) {
138 String message =
139 resources.getMessage("error.managerName.bad",
140 sb.toString());
141 getServlet().log(message);
142 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
143 return (null);
144 }
145
146 // Fill in the form values for display and editing
147 ContextForm contextFm = new ContextForm();
148 session.setAttribute("contextForm", contextFm);
149 contextFm.setAdminAction("Edit");
150 contextFm.setObjectName(cname.toString());
151 contextFm.setLoaderObjectName(lname.toString());
152 contextFm.setManagerObjectName(mname.toString());
153 sb = new StringBuffer();
154 sb.append(resources.getMessage(locale, "server.service.treeBuilder.context"));
155 sb.append(" (");
156 sb.append(path);
157 sb.append(")");
158 contextFm.setNodeLabel(sb.toString());
159 contextFm.setBooleanVals(Lists.getBooleanValues());
160
161 String attribute = null;
162 try {
163
164 // Copy scalar properties
165 attribute = "path";
166 contextFm.setPath
167 ((String) mBServer.getAttribute(cname, attribute));
168 attribute = "cookies";
169 contextFm.setCookies
170 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
171 attribute = "crossContext";
172 contextFm.setCrossContext
173 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
174 attribute = "docBase";
175 contextFm.setDocBase
176 ((String) mBServer.getAttribute(cname, attribute));
177 attribute = "workDir";
178 contextFm.setWorkDir
179 ((String) mBServer.getAttribute(cname, attribute));
180 attribute = "useNaming";
181 contextFm.setUseNaming
182 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
183 attribute = "reloadable";
184 contextFm.setReloadable
185 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
186 attribute = "swallowOutput";
187 contextFm.setSwallowOutput
188 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
189 attribute = "override";
190 contextFm.setOverride
191 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
192 attribute = "privileged";
193 contextFm.setPrivileged
194 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
195
196 attribute = "antiJARLocking";
197 contextFm.setAntiJarLocking
198 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
199 attribute = "antiResourceLocking";
200 contextFm.setAntiResourceLocking
201 (((Boolean) mBServer.getAttribute(cname, attribute)).toString());
202 // loader properties
203 //attribute = "checkInterval";
204 //contextFm.setLdrCheckInterval
205 // (((Integer) mBServer.getAttribute(lname, attribute)).toString());
206 attribute = "reloadable";
207 contextFm.setLdrReloadable
208 (((Boolean) mBServer.getAttribute(lname, attribute)).toString());
209
210 // manager properties
211 attribute = "entropy";
212 contextFm.setMgrSessionIDInit
213 ((String) mBServer.getAttribute(mname, attribute));
214 attribute = "maxActiveSessions";
215 contextFm.setMgrMaxSessions
216 (((Integer) mBServer.getAttribute(mname, attribute)).toString());
217 //attribute = "checkInterval";
218 //contextFm.setMgrCheckInterval
219 // (((Integer) mBServer.getAttribute(mname, attribute)).toString());
220
221 } catch (Throwable t) {
222 getServlet().log
223 (resources.getMessage(locale, "users.error.attribute.get",
224 attribute), t);
225 response.sendError
226 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
227 resources.getMessage(locale, "users.error.attribute.get",
228 attribute));
229 return (null);
230 }
231
232 // Forward to the context display page
233 return (mapping.findForward("Context"));
234
235 }
236
237
238 }